Compare commits

...

No commits in common. "main" and "aad99e0d3ba06c77e09e7eb4cbc229da34f81d5b" have entirely different histories.

11 changed files with 71 additions and 114 deletions

View File

@ -7,13 +7,13 @@ namespace SoundFilter {
internal class Commands : IDisposable {
private const string Name = "/soundfilter";
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
public Commands(Plugin plugin) {
public Commands(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.Plugin.CommandManager.AddHandler(Name, new CommandInfo(this.OnCommand) {
HelpMessage = $"Toggle the {Plugin.Name} config",
HelpMessage = $"Toggle the {this.Plugin.Name} config",
});
}
@ -31,9 +31,9 @@ namespace SoundFilter {
var split = args.Split(' ');
if (split.Length < 1) {
chat.PrintError($"[{Plugin.Name}] {Language.CommandNotEnoughArguments}");
chat.PrintError($"[{Plugin.Name}] /soundfilter log");
chat.PrintError($"[{Plugin.Name}] /soundfilter <enable|disable|toggle> [filter name]");
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandNotEnoughArguments}");
chat.PrintError($"[{this.Plugin.Name}] /soundfilter log");
chat.PrintError($"[{this.Plugin.Name}] /soundfilter <enable|disable|toggle> [filter name]");
return;
}
@ -46,7 +46,7 @@ namespace SoundFilter {
var filterName = split.Length > 1 ? string.Join(" ", split.Skip(1)) : null;
var filter = filterName == null ? null : this.Plugin.Config.Filters.FirstOrDefault(filter => filter.Name == filterName);
if (filterName != null && filter == null) {
chat.PrintError($"[{Plugin.Name}] {Language.CommandNoSuchFilter}");
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandNoSuchFilter}");
return;
}
@ -58,7 +58,7 @@ namespace SoundFilter {
_ => null,
};
if (enabled == null) {
chat.PrintError($"[{Plugin.Name}] {Language.CommandInvalidSubcommand}");
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandInvalidSubcommand}");
return;
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Dalamud.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -37,7 +38,7 @@ namespace SoundFilter.Config {
old["Version"] = 2;
}
public static Configuration LoadConfiguration(Plugin plugin) {
public static Configuration LoadConfiguration(SoundFilterPlugin plugin) {
var fileInfo = plugin.Interface.ConfigFile;
var text = fileInfo.Exists
? File.ReadAllText(fileInfo.FullName)
@ -69,7 +70,7 @@ namespace SoundFilter.Config {
MigrateV1(config);
break;
default:
Plugin.Log.Warning($"Tried to migrate from an unknown version: {version}");
PluginLog.Warning($"Tried to migrate from an unknown version: {version}");
goto DefaultConfiguration;
}

View File

@ -4,7 +4,7 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Hooking;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
namespace SoundFilter {
@ -16,7 +16,7 @@ namespace SoundFilter {
internal const string GetResourceAsync = "E8 ?? ?? ?? ?? 48 8B D8 EB 07 F0 FF 83";
internal const string LoadSoundFile = "E8 ?? ?? ?? ?? 48 85 C0 75 04 B0 F6";
internal const string MusicManagerOffset = "48 89 87 ?? ?? ?? ?? 49 8B CF E8 ?? ?? ?? ?? 48 8B 8F";
internal const string MusicManagerOffset = "48 8B 8E ?? ?? ?? ?? 39 78 20 0F 94 C2 45 33 C0";
}
// Updated: 5.55
@ -47,7 +47,7 @@ namespace SoundFilter {
#endregion
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
private bool WasStreamingEnabled { get; }
private ConcurrentDictionary<IntPtr, string> Scds { get; } = new();
@ -60,12 +60,12 @@ namespace SoundFilter {
private IntPtr MusicManager {
get {
if (!this.Plugin.SigScanner.TryScanText(Signatures.MusicManagerOffset, out var instructionPtr)) {
Plugin.Log.Warning("Could not find music manager");
PluginLog.LogWarning("Could not find music manager");
return IntPtr.Zero;
}
var offset = *(int*) (instructionPtr + 3);
return *(IntPtr*) ((IntPtr) Framework.Instance() + offset);
return *(IntPtr*) (this.Plugin.Framework.Address.BaseAddress + offset);
}
}
@ -88,7 +88,7 @@ namespace SoundFilter {
}
}
internal Filter(Plugin plugin) {
internal Filter(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.WasStreamingEnabled = this.Streaming;
@ -121,28 +121,28 @@ namespace SoundFilter {
// write a pointer to the empty scd
Marshal.WriteIntPtr(infoPtr + 8, noSoundPtr);
// specify where the game should offset from for the sound index
Marshal.WriteInt32(infoPtr + 0x88, 0x54);
Marshal.WriteInt32(infoPtr + 0x90, 0x54);
// specify the number of sounds in the file
Marshal.WriteInt16(infoPtr + 0x94, 0);
Marshal.WriteInt16(infoPtr + 0x9C, 0);
return (noSoundPtr, infoPtr);
}
internal void Enable() {
if (this.PlaySpecificSoundHook == null && this.Plugin.SigScanner.TryScanText(Signatures.PlaySpecificSound, out var playPtr)) {
this.PlaySpecificSoundHook = this.Plugin.GameInteropProvider.HookFromAddress<PlaySpecificSoundDelegate>(playPtr, this.PlaySpecificSoundDetour);
this.PlaySpecificSoundHook = new Hook<PlaySpecificSoundDelegate>(playPtr, this.PlaySpecificSoundDetour);
}
if (this.GetResourceSyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceSync, out var syncPtr)) {
this.GetResourceSyncHook = this.Plugin.GameInteropProvider.HookFromAddress<GetResourceSyncPrototype>(syncPtr, this.GetResourceSyncDetour);
this.GetResourceSyncHook = new Hook<GetResourceSyncPrototype>(syncPtr, this.GetResourceSyncDetour);
}
if (this.GetResourceAsyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceAsync, out var asyncPtr)) {
this.GetResourceAsyncHook = this.Plugin.GameInteropProvider.HookFromAddress<GetResourceAsyncPrototype>(asyncPtr, this.GetResourceAsyncDetour);
this.GetResourceAsyncHook = new Hook<GetResourceAsyncPrototype>(asyncPtr, this.GetResourceAsyncDetour);
}
if (this.LoadSoundFileHook == null && this.Plugin.SigScanner.TryScanText(Signatures.LoadSoundFile, out var soundPtr)) {
this.LoadSoundFileHook = this.Plugin.GameInteropProvider.HookFromAddress<LoadSoundFileDelegate>(soundPtr, this.LoadSoundFileDetour);
this.LoadSoundFileHook = new Hook<LoadSoundFileDelegate>(soundPtr, this.LoadSoundFileDetour);
}
this.PlaySpecificSoundHook?.Enable();
@ -175,10 +175,9 @@ namespace SoundFilter {
var shouldFilter = this.PlaySpecificSoundDetourInner(a1, idx);
if (shouldFilter) {
a1 = (long) this.InfoPtr;
idx = 0;
}
} catch (Exception ex) {
Plugin.Log.Error(ex, "Error in PlaySpecificSoundDetour");
PluginLog.LogError(ex, "Error in PlaySpecificSoundDetour");
}
return this.PlaySpecificSoundHook!.Original(a1, idx);
@ -256,7 +255,7 @@ namespace SoundFilter {
this.Scds[dataPtr] = name;
}
} catch (Exception ex) {
Plugin.Log.Error(ex, "Error in LoadSoundFileDetour");
PluginLog.LogError(ex, "Error in LoadSoundFileDetour");
}
return ret;

View File

@ -1,46 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7-windows</TargetFramework>
<Version>1.4.13</Version>
<TargetFramework>net5-windows</TargetFramework>
<Version>1.4.5</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<PropertyGroup>
<DalamudLibPath>$(AppData)\XIVLauncher\addon\Hooks\dev</DalamudLibPath>
</PropertyGroup>
<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)</DalamudLibPath>
<Dalamud>$(AppData)\XIVLauncher\addon\Hooks\dev</Dalamud>
</PropertyGroup>
<PropertyGroup Condition="'$(IsCI)' == 'true'">
<DalamudLibPath>$(HOME)/dalamud</DalamudLibPath>
<Dalamud>$(HOME)/dalamud</Dalamud>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)\Dalamud.dll</HintPath>
<HintPath>$(Dalamud)\Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>$(DalamudLibPath)\FFXIVClientStructs.dll</HintPath>
<HintPath>$(Dalamud)\FFXIVClientStructs.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DalamudLibPath)\ImGui.NET.dll</HintPath>
<HintPath>$(Dalamud)\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)\ImGuiScene.dll</HintPath>
<HintPath>$(Dalamud)\ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)\Newtonsoft.Json.dll</HintPath>
<HintPath>$(Dalamud)\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
@ -50,7 +45,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Language.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\gaya_nosound.scd" />
<EmbeddedResource Include="Resources\gaya_nosound.scd"/>
</ItemGroup>
<ItemGroup>
@ -62,9 +57,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Fody" Version="6.8.0" PrivateAssets="all" />
<PackageReference Include="Resourcer.Fody" Version="1.8.1" PrivateAssets="all" />
<PackageReference Include="DalamudPackager" Version="2.1.2"/>
<PackageReference Include="DotNet.Glob" Version="3.1.2"/>
<PackageReference Include="Fody" Version="6.5.2" PrivateAssets="all"/>
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
</ItemGroup>
<ItemGroup>
<Content Include="..\icon.png" Link="images/icon.png" CopyToOutputDirectory="PreserveNewest" Visible="false"/>
</ItemGroup>
</Project>

View File

@ -1,5 +1,5 @@
name: Sound Filter
author: Anna
author: ascclemens
punchline: Filter any game sound.
description: |-
Filters any sound or set of sounds from the game.
@ -10,4 +10,4 @@ description: |-
Icons: filter by Kirby Wu from the Noun Project
and Sound by Gregor Cresnar from the Noun Project
repo_url: https://git.anna.lgbt/anna/SoundFilter
repo_url: https://git.sr.ht/jkcclemens/SoundFilter

View File

@ -1,46 +1,41 @@
using Dalamud.Game;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using SoundFilter.Config;
using SoundFilter.Resources;
using SoundFilter.Ui;
namespace SoundFilter {
// ReSharper disable once ClassNeverInstantiated.Global
internal class Plugin : IDalamudPlugin {
public static string Name => "Sound Filter";
[PluginService]
internal static IPluginLog Log { get; private set; } = null!;
internal class SoundFilterPlugin : IDalamudPlugin {
public string Name => "Sound Filter";
[PluginService]
internal DalamudPluginInterface Interface { get; init; } = null!;
[PluginService]
internal IChatGui ChatGui { get; init; } = null!;
internal ChatGui ChatGui { get; init; } = null!;
[PluginService]
internal ICommandManager CommandManager { get; init; } = null!;
internal CommandManager CommandManager { get; init; } = null!;
[PluginService]
internal IFramework Framework { get; init; } = null!;
internal Framework Framework { get; init; } = null!;
[PluginService]
internal ISigScanner SigScanner { get; init; } = null!;
[PluginService]
internal IGameInteropProvider GameInteropProvider { get; init; } = null!;
internal SigScanner SigScanner { get; init; } = null!;
internal Configuration Config { get; }
internal Filter Filter { get; }
internal PluginUi Ui { get; }
private Commands Commands { get; }
public Plugin() {
public SoundFilterPlugin() {
this.Config = Migrator.LoadConfiguration(this);
this.Config.Initialise(this.Interface);
@ -56,12 +51,12 @@ namespace SoundFilter {
return;
}
var message = string.Format(Language.LoadWarning, Name);
this.ChatGui.Print(new XivChatEntry {
Name = Name,
var message = string.Format(Language.LoadWarning, this.Name);
this.ChatGui.PrintChat(new XivChatEntry {
Name = this.Name,
Message = new SeString(
new UIForegroundPayload(502),
new TextPayload($"[{Name}] {message}"),
new TextPayload($"[{this.Name}] {message}"),
new UIForegroundPayload(0)
),
});

View File

@ -9,19 +9,19 @@ using SoundFilter.Resources;
namespace SoundFilter.Ui {
internal class AddFilter {
private Guid Id { get; } = Guid.NewGuid();
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
private CustomFilter? Filter { get; }
private string _filterName = string.Empty;
private string _newSoundPath = string.Empty;
private readonly List<string> _soundPaths = new();
internal AddFilter(Plugin plugin) {
internal AddFilter(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.Filter = null;
}
internal AddFilter(Plugin plugin, CustomFilter filter) {
internal AddFilter(SoundFilterPlugin plugin, CustomFilter filter) {
this.Plugin = plugin;
this.Filter = filter;

View File

@ -1,14 +1,15 @@
using System;
using System.Globalization;
using Dalamud.Logging;
using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class PluginUi : IDisposable {
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
internal Settings Settings { get; }
private SoundLog SoundLog { get; }
internal PluginUi(Plugin plugin) {
internal PluginUi(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.ConfigureLanguage();
@ -33,7 +34,7 @@ namespace SoundFilter.Ui {
try {
Language.Culture = new CultureInfo(langCode);
} catch (Exception ex) {
Plugin.Log.Error(ex, $"Could not set culture to {langCode} - falling back to default");
PluginLog.LogError(ex, $"Could not set culture to {langCode} - falling back to default");
Language.Culture = CultureInfo.DefaultThreadCurrentUICulture;
}
}

View File

@ -6,14 +6,14 @@ using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class Settings : IDisposable {
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
private AddFilter AddFilter { get; }
private AddFilter? EditFilter { get; set; }
private bool _showWindow;
private int _dragging = -1;
internal Settings(Plugin plugin) {
internal Settings(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.AddFilter = new AddFilter(plugin);
@ -48,7 +48,7 @@ namespace SoundFilter.Ui {
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
var windowTitle = string.Format(Language.SettingsWindowTitle, Plugin.Name);
var windowTitle = string.Format(Language.SettingsWindowTitle, this.Plugin.Name);
if (!ImGui.Begin($"{windowTitle}###soundfilter-settings", ref this._showWindow)) {
ImGui.End();
return;
@ -136,7 +136,6 @@ namespace SoundFilter.Ui {
if (drag != null && drag.Value.dst < this.Plugin.Config.Filters.Count && drag.Value.dst >= 0) {
this._dragging = drag.Value.dst;
// ReSharper disable once SwapViaDeconstruction
var temp = this.Plugin.Config.Filters[drag.Value.src];
this.Plugin.Config.Filters[drag.Value.src] = this.Plugin.Config.Filters[drag.Value.dst];
this.Plugin.Config.Filters[drag.Value.dst] = temp;

View File

@ -7,11 +7,11 @@ using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class SoundLog {
private Plugin Plugin { get; }
private SoundFilterPlugin Plugin { get; }
private string _search = string.Empty;
internal SoundLog(Plugin plugin) {
internal SoundLog(SoundFilterPlugin plugin) {
this.Plugin = plugin;
}
@ -23,6 +23,7 @@ namespace SoundFilter.Ui {
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
if (!ImGui.Begin(Language.LogWindowTitle, ref this.Plugin.Config.ShowLog)) {
this.Plugin.Config.Save();
ImGui.End();
return;
}
@ -66,10 +67,6 @@ namespace SoundFilter.Ui {
ImGui.EndChild();
}
// god disabled this frame
if (!this.Plugin.Config.ShowLog) {
this.Plugin.Config.Save();
}
ImGui.End();
}

View File

@ -1,34 +0,0 @@
{
"version": 1,
"dependencies": {
"net7.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.12, )",
"resolved": "2.1.12",
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
},
"DotNet.Glob": {
"type": "Direct",
"requested": "[3.1.3, )",
"resolved": "3.1.3",
"contentHash": "hOfHw7MLJw/tbXaFwR1oiDb+dIXDp8URTxp5Pco42OOhiw77wrUNx6v6syNygHZbWwYdXQocL2Mo1l5FnfDVjg=="
},
"Fody": {
"type": "Direct",
"requested": "[6.8.0, )",
"resolved": "6.8.0",
"contentHash": "hfZ/f8Mezt8aTkgv9nsvFdYoQ809/AqwsJlOGOPYIfBcG2aAIG3v3ex9d8ZqQuFYyMoucjRg4eKy3VleeGodKQ=="
},
"Resourcer.Fody": {
"type": "Direct",
"requested": "[1.8.1, )",
"resolved": "1.8.1",
"contentHash": "FPeK4jKyyX5+mIjTnHNReGZk2/2xDhmu44UsBI5w9WEhbr4oTMmht3rnBr46A+GCGepC4+2N41K4vExDYiGNVQ==",
"dependencies": {
"Fody": "6.6.4"
}
}
}
}
}