refactor: update for api 9
This commit is contained in:
parent
3c94e07c13
commit
994d5134a5
|
@ -7,13 +7,13 @@ namespace SoundFilter {
|
||||||
internal class Commands : IDisposable {
|
internal class Commands : IDisposable {
|
||||||
private const string Name = "/soundfilter";
|
private const string Name = "/soundfilter";
|
||||||
|
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
|
|
||||||
public Commands(SoundFilterPlugin plugin) {
|
public Commands(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
|
||||||
this.Plugin.CommandManager.AddHandler(Name, new CommandInfo(this.OnCommand) {
|
this.Plugin.CommandManager.AddHandler(Name, new CommandInfo(this.OnCommand) {
|
||||||
HelpMessage = $"Toggle the {this.Plugin.Name} config",
|
HelpMessage = $"Toggle the {Plugin.Name} config",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ namespace SoundFilter {
|
||||||
|
|
||||||
var split = args.Split(' ');
|
var split = args.Split(' ');
|
||||||
if (split.Length < 1) {
|
if (split.Length < 1) {
|
||||||
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandNotEnoughArguments}");
|
chat.PrintError($"[{Plugin.Name}] {Language.CommandNotEnoughArguments}");
|
||||||
chat.PrintError($"[{this.Plugin.Name}] /soundfilter log");
|
chat.PrintError($"[{Plugin.Name}] /soundfilter log");
|
||||||
chat.PrintError($"[{this.Plugin.Name}] /soundfilter <enable|disable|toggle> [filter name]");
|
chat.PrintError($"[{Plugin.Name}] /soundfilter <enable|disable|toggle> [filter name]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ namespace SoundFilter {
|
||||||
var filterName = split.Length > 1 ? string.Join(" ", split.Skip(1)) : null;
|
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);
|
var filter = filterName == null ? null : this.Plugin.Config.Filters.FirstOrDefault(filter => filter.Name == filterName);
|
||||||
if (filterName != null && filter == null) {
|
if (filterName != null && filter == null) {
|
||||||
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandNoSuchFilter}");
|
chat.PrintError($"[{Plugin.Name}] {Language.CommandNoSuchFilter}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace SoundFilter {
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandInvalidSubcommand}");
|
chat.PrintError($"[{Plugin.Name}] {Language.CommandInvalidSubcommand}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Dalamud.Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ namespace SoundFilter.Config {
|
||||||
old["Version"] = 2;
|
old["Version"] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Configuration LoadConfiguration(SoundFilterPlugin plugin) {
|
public static Configuration LoadConfiguration(Plugin plugin) {
|
||||||
var fileInfo = plugin.Interface.ConfigFile;
|
var fileInfo = plugin.Interface.ConfigFile;
|
||||||
var text = fileInfo.Exists
|
var text = fileInfo.Exists
|
||||||
? File.ReadAllText(fileInfo.FullName)
|
? File.ReadAllText(fileInfo.FullName)
|
||||||
|
@ -70,7 +69,7 @@ namespace SoundFilter.Config {
|
||||||
MigrateV1(config);
|
MigrateV1(config);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PluginLog.Warning($"Tried to migrate from an unknown version: {version}");
|
Plugin.Log.Warning($"Tried to migrate from an unknown version: {version}");
|
||||||
goto DefaultConfiguration;
|
goto DefaultConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Dalamud.Hooking;
|
using Dalamud.Hooking;
|
||||||
using Dalamud.Logging;
|
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
|
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ namespace SoundFilter {
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
private bool WasStreamingEnabled { get; }
|
private bool WasStreamingEnabled { get; }
|
||||||
|
|
||||||
private ConcurrentDictionary<IntPtr, string> Scds { get; } = new();
|
private ConcurrentDictionary<IntPtr, string> Scds { get; } = new();
|
||||||
|
@ -61,7 +60,7 @@ namespace SoundFilter {
|
||||||
private IntPtr MusicManager {
|
private IntPtr MusicManager {
|
||||||
get {
|
get {
|
||||||
if (!this.Plugin.SigScanner.TryScanText(Signatures.MusicManagerOffset, out var instructionPtr)) {
|
if (!this.Plugin.SigScanner.TryScanText(Signatures.MusicManagerOffset, out var instructionPtr)) {
|
||||||
PluginLog.LogWarning("Could not find music manager");
|
Plugin.Log.Warning("Could not find music manager");
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ namespace SoundFilter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Filter(SoundFilterPlugin plugin) {
|
internal Filter(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
|
||||||
this.WasStreamingEnabled = this.Streaming;
|
this.WasStreamingEnabled = this.Streaming;
|
||||||
|
@ -131,19 +130,19 @@ namespace SoundFilter {
|
||||||
|
|
||||||
internal void Enable() {
|
internal void Enable() {
|
||||||
if (this.PlaySpecificSoundHook == null && this.Plugin.SigScanner.TryScanText(Signatures.PlaySpecificSound, out var playPtr)) {
|
if (this.PlaySpecificSoundHook == null && this.Plugin.SigScanner.TryScanText(Signatures.PlaySpecificSound, out var playPtr)) {
|
||||||
this.PlaySpecificSoundHook = Hook<PlaySpecificSoundDelegate>.FromAddress(playPtr, this.PlaySpecificSoundDetour);
|
this.PlaySpecificSoundHook = this.Plugin.GameInteropProvider.HookFromAddress<PlaySpecificSoundDelegate>(playPtr, this.PlaySpecificSoundDetour);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.GetResourceSyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceSync, out var syncPtr)) {
|
if (this.GetResourceSyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceSync, out var syncPtr)) {
|
||||||
this.GetResourceSyncHook = Hook<GetResourceSyncPrototype>.FromAddress(syncPtr, this.GetResourceSyncDetour);
|
this.GetResourceSyncHook = this.Plugin.GameInteropProvider.HookFromAddress<GetResourceSyncPrototype>(syncPtr, this.GetResourceSyncDetour);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.GetResourceAsyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceAsync, out var asyncPtr)) {
|
if (this.GetResourceAsyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceAsync, out var asyncPtr)) {
|
||||||
this.GetResourceAsyncHook = Hook<GetResourceAsyncPrototype>.FromAddress(asyncPtr, this.GetResourceAsyncDetour);
|
this.GetResourceAsyncHook = this.Plugin.GameInteropProvider.HookFromAddress<GetResourceAsyncPrototype>(asyncPtr, this.GetResourceAsyncDetour);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.LoadSoundFileHook == null && this.Plugin.SigScanner.TryScanText(Signatures.LoadSoundFile, out var soundPtr)) {
|
if (this.LoadSoundFileHook == null && this.Plugin.SigScanner.TryScanText(Signatures.LoadSoundFile, out var soundPtr)) {
|
||||||
this.LoadSoundFileHook = Hook<LoadSoundFileDelegate>.FromAddress(soundPtr, this.LoadSoundFileDetour);
|
this.LoadSoundFileHook = this.Plugin.GameInteropProvider.HookFromAddress<LoadSoundFileDelegate>(soundPtr, this.LoadSoundFileDetour);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.PlaySpecificSoundHook?.Enable();
|
this.PlaySpecificSoundHook?.Enable();
|
||||||
|
@ -179,7 +178,7 @@ namespace SoundFilter {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
PluginLog.LogError(ex, "Error in PlaySpecificSoundDetour");
|
Plugin.Log.Error(ex, "Error in PlaySpecificSoundDetour");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.PlaySpecificSoundHook!.Original(a1, idx);
|
return this.PlaySpecificSoundHook!.Original(a1, idx);
|
||||||
|
@ -257,7 +256,7 @@ namespace SoundFilter {
|
||||||
this.Scds[dataPtr] = name;
|
this.Scds[dataPtr] = name;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
PluginLog.LogError(ex, "Error in LoadSoundFileDetour");
|
Plugin.Log.Error(ex, "Error in LoadSoundFileDetour");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,41 +1,46 @@
|
||||||
using Dalamud.Game;
|
using Dalamud.Game;
|
||||||
using Dalamud.Game.Command;
|
|
||||||
using Dalamud.Game.Gui;
|
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
using Dalamud.Game.Text.SeStringHandling;
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||||
using Dalamud.IoC;
|
using Dalamud.IoC;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
using SoundFilter.Config;
|
using SoundFilter.Config;
|
||||||
using SoundFilter.Resources;
|
using SoundFilter.Resources;
|
||||||
using SoundFilter.Ui;
|
using SoundFilter.Ui;
|
||||||
|
|
||||||
namespace SoundFilter {
|
namespace SoundFilter {
|
||||||
// ReSharper disable once ClassNeverInstantiated.Global
|
// ReSharper disable once ClassNeverInstantiated.Global
|
||||||
internal class SoundFilterPlugin : IDalamudPlugin {
|
internal class Plugin : IDalamudPlugin {
|
||||||
public string Name => "Sound Filter";
|
public static string Name => "Sound Filter";
|
||||||
|
|
||||||
|
[PluginService]
|
||||||
|
internal static IPluginLog Log { get; private set; } = null!;
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal DalamudPluginInterface Interface { get; init; } = null!;
|
internal DalamudPluginInterface Interface { get; init; } = null!;
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal ChatGui ChatGui { get; init; } = null!;
|
internal IChatGui ChatGui { get; init; } = null!;
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal CommandManager CommandManager { get; init; } = null!;
|
internal ICommandManager CommandManager { get; init; } = null!;
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal Framework Framework { get; init; } = null!;
|
internal IFramework Framework { get; init; } = null!;
|
||||||
|
|
||||||
[PluginService]
|
[PluginService]
|
||||||
internal SigScanner SigScanner { get; init; } = null!;
|
internal ISigScanner SigScanner { get; init; } = null!;
|
||||||
|
|
||||||
|
[PluginService]
|
||||||
|
internal IGameInteropProvider GameInteropProvider { get; init; } = null!;
|
||||||
|
|
||||||
internal Configuration Config { get; }
|
internal Configuration Config { get; }
|
||||||
internal Filter Filter { get; }
|
internal Filter Filter { get; }
|
||||||
internal PluginUi Ui { get; }
|
internal PluginUi Ui { get; }
|
||||||
private Commands Commands { get; }
|
private Commands Commands { get; }
|
||||||
|
|
||||||
public SoundFilterPlugin() {
|
public Plugin() {
|
||||||
this.Config = Migrator.LoadConfiguration(this);
|
this.Config = Migrator.LoadConfiguration(this);
|
||||||
this.Config.Initialise(this.Interface);
|
this.Config.Initialise(this.Interface);
|
||||||
|
|
||||||
|
@ -51,12 +56,12 @@ namespace SoundFilter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = string.Format(Language.LoadWarning, this.Name);
|
var message = string.Format(Language.LoadWarning, Name);
|
||||||
this.ChatGui.PrintChat(new XivChatEntry {
|
this.ChatGui.Print(new XivChatEntry {
|
||||||
Name = this.Name,
|
Name = Name,
|
||||||
Message = new SeString(
|
Message = new SeString(
|
||||||
new UIForegroundPayload(502),
|
new UIForegroundPayload(502),
|
||||||
new TextPayload($"[{this.Name}] {message}"),
|
new TextPayload($"[{Name}] {message}"),
|
||||||
new UIForegroundPayload(0)
|
new UIForegroundPayload(0)
|
||||||
),
|
),
|
||||||
});
|
});
|
|
@ -9,19 +9,19 @@ using SoundFilter.Resources;
|
||||||
namespace SoundFilter.Ui {
|
namespace SoundFilter.Ui {
|
||||||
internal class AddFilter {
|
internal class AddFilter {
|
||||||
private Guid Id { get; } = Guid.NewGuid();
|
private Guid Id { get; } = Guid.NewGuid();
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
private CustomFilter? Filter { get; }
|
private CustomFilter? Filter { get; }
|
||||||
|
|
||||||
private string _filterName = string.Empty;
|
private string _filterName = string.Empty;
|
||||||
private string _newSoundPath = string.Empty;
|
private string _newSoundPath = string.Empty;
|
||||||
private readonly List<string> _soundPaths = new();
|
private readonly List<string> _soundPaths = new();
|
||||||
|
|
||||||
internal AddFilter(SoundFilterPlugin plugin) {
|
internal AddFilter(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
this.Filter = null;
|
this.Filter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal AddFilter(SoundFilterPlugin plugin, CustomFilter filter) {
|
internal AddFilter(Plugin plugin, CustomFilter filter) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
this.Filter = filter;
|
this.Filter = filter;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Dalamud.Logging;
|
|
||||||
using SoundFilter.Resources;
|
using SoundFilter.Resources;
|
||||||
|
|
||||||
namespace SoundFilter.Ui {
|
namespace SoundFilter.Ui {
|
||||||
public class PluginUi : IDisposable {
|
public class PluginUi : IDisposable {
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
internal Settings Settings { get; }
|
internal Settings Settings { get; }
|
||||||
private SoundLog SoundLog { get; }
|
private SoundLog SoundLog { get; }
|
||||||
|
|
||||||
internal PluginUi(SoundFilterPlugin plugin) {
|
internal PluginUi(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
|
||||||
this.ConfigureLanguage();
|
this.ConfigureLanguage();
|
||||||
|
@ -34,7 +33,7 @@ namespace SoundFilter.Ui {
|
||||||
try {
|
try {
|
||||||
Language.Culture = new CultureInfo(langCode);
|
Language.Culture = new CultureInfo(langCode);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
PluginLog.LogError(ex, $"Could not set culture to {langCode} - falling back to default");
|
Plugin.Log.Error(ex, $"Could not set culture to {langCode} - falling back to default");
|
||||||
Language.Culture = CultureInfo.DefaultThreadCurrentUICulture;
|
Language.Culture = CultureInfo.DefaultThreadCurrentUICulture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ using SoundFilter.Resources;
|
||||||
|
|
||||||
namespace SoundFilter.Ui {
|
namespace SoundFilter.Ui {
|
||||||
public class Settings : IDisposable {
|
public class Settings : IDisposable {
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
private AddFilter AddFilter { get; }
|
private AddFilter AddFilter { get; }
|
||||||
private AddFilter? EditFilter { get; set; }
|
private AddFilter? EditFilter { get; set; }
|
||||||
|
|
||||||
private bool _showWindow;
|
private bool _showWindow;
|
||||||
private int _dragging = -1;
|
private int _dragging = -1;
|
||||||
|
|
||||||
internal Settings(SoundFilterPlugin plugin) {
|
internal Settings(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
this.AddFilter = new AddFilter(plugin);
|
this.AddFilter = new AddFilter(plugin);
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ namespace SoundFilter.Ui {
|
||||||
|
|
||||||
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
|
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
|
||||||
|
|
||||||
var windowTitle = string.Format(Language.SettingsWindowTitle, this.Plugin.Name);
|
var windowTitle = string.Format(Language.SettingsWindowTitle, Plugin.Name);
|
||||||
if (!ImGui.Begin($"{windowTitle}###soundfilter-settings", ref this._showWindow)) {
|
if (!ImGui.Begin($"{windowTitle}###soundfilter-settings", ref this._showWindow)) {
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,11 +7,11 @@ using SoundFilter.Resources;
|
||||||
|
|
||||||
namespace SoundFilter.Ui {
|
namespace SoundFilter.Ui {
|
||||||
public class SoundLog {
|
public class SoundLog {
|
||||||
private SoundFilterPlugin Plugin { get; }
|
private Plugin Plugin { get; }
|
||||||
|
|
||||||
private string _search = string.Empty;
|
private string _search = string.Empty;
|
||||||
|
|
||||||
internal SoundLog(SoundFilterPlugin plugin) {
|
internal SoundLog(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue