refactor: update for api 9

This commit is contained in:
Anna 2023-09-28 02:29:56 -04:00
parent 3c94e07c13
commit 994d5134a5
Signed by: anna
GPG Key ID: D0943384CD9F87D1
8 changed files with 48 additions and 46 deletions

View File

@ -7,13 +7,13 @@ namespace SoundFilter {
internal class Commands : IDisposable {
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.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(' ');
if (split.Length < 1) {
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]");
chat.PrintError($"[{Plugin.Name}] {Language.CommandNotEnoughArguments}");
chat.PrintError($"[{Plugin.Name}] /soundfilter log");
chat.PrintError($"[{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($"[{this.Plugin.Name}] {Language.CommandNoSuchFilter}");
chat.PrintError($"[{Plugin.Name}] {Language.CommandNoSuchFilter}");
return;
}
@ -58,7 +58,7 @@ namespace SoundFilter {
_ => null,
};
if (enabled == null) {
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandInvalidSubcommand}");
chat.PrintError($"[{Plugin.Name}] {Language.CommandInvalidSubcommand}");
return;
}

View File

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

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Hooking;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
@ -48,7 +47,7 @@ namespace SoundFilter {
#endregion
private SoundFilterPlugin Plugin { get; }
private Plugin Plugin { get; }
private bool WasStreamingEnabled { get; }
private ConcurrentDictionary<IntPtr, string> Scds { get; } = new();
@ -61,7 +60,7 @@ namespace SoundFilter {
private IntPtr MusicManager {
get {
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;
}
@ -89,7 +88,7 @@ namespace SoundFilter {
}
}
internal Filter(SoundFilterPlugin plugin) {
internal Filter(Plugin plugin) {
this.Plugin = plugin;
this.WasStreamingEnabled = this.Streaming;
@ -131,19 +130,19 @@ namespace SoundFilter {
internal void Enable() {
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)) {
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)) {
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)) {
this.LoadSoundFileHook = Hook<LoadSoundFileDelegate>.FromAddress(soundPtr, this.LoadSoundFileDetour);
this.LoadSoundFileHook = this.Plugin.GameInteropProvider.HookFromAddress<LoadSoundFileDelegate>(soundPtr, this.LoadSoundFileDetour);
}
this.PlaySpecificSoundHook?.Enable();
@ -179,7 +178,7 @@ namespace SoundFilter {
idx = 0;
}
} catch (Exception ex) {
PluginLog.LogError(ex, "Error in PlaySpecificSoundDetour");
Plugin.Log.Error(ex, "Error in PlaySpecificSoundDetour");
}
return this.PlaySpecificSoundHook!.Original(a1, idx);
@ -257,7 +256,7 @@ namespace SoundFilter {
this.Scds[dataPtr] = name;
}
} catch (Exception ex) {
PluginLog.LogError(ex, "Error in LoadSoundFileDetour");
Plugin.Log.Error(ex, "Error in LoadSoundFileDetour");
}
return ret;

View File

@ -1,41 +1,46 @@
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 SoundFilterPlugin : IDalamudPlugin {
public string Name => "Sound Filter";
internal class Plugin : IDalamudPlugin {
public static string Name => "Sound Filter";
[PluginService]
internal static IPluginLog Log { get; private set; } = null!;
[PluginService]
internal DalamudPluginInterface Interface { get; init; } = null!;
[PluginService]
internal ChatGui ChatGui { get; init; } = null!;
internal IChatGui ChatGui { get; init; } = null!;
[PluginService]
internal CommandManager CommandManager { get; init; } = null!;
internal ICommandManager CommandManager { get; init; } = null!;
[PluginService]
internal Framework Framework { get; init; } = null!;
internal IFramework Framework { get; init; } = null!;
[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 Filter Filter { get; }
internal PluginUi Ui { get; }
private Commands Commands { get; }
public SoundFilterPlugin() {
public Plugin() {
this.Config = Migrator.LoadConfiguration(this);
this.Config.Initialise(this.Interface);
@ -51,12 +56,12 @@ namespace SoundFilter {
return;
}
var message = string.Format(Language.LoadWarning, this.Name);
this.ChatGui.PrintChat(new XivChatEntry {
Name = this.Name,
var message = string.Format(Language.LoadWarning, Name);
this.ChatGui.Print(new XivChatEntry {
Name = Name,
Message = new SeString(
new UIForegroundPayload(502),
new TextPayload($"[{this.Name}] {message}"),
new TextPayload($"[{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 SoundFilterPlugin Plugin { get; }
private Plugin Plugin { get; }
private CustomFilter? Filter { get; }
private string _filterName = string.Empty;
private string _newSoundPath = string.Empty;
private readonly List<string> _soundPaths = new();
internal AddFilter(SoundFilterPlugin plugin) {
internal AddFilter(Plugin plugin) {
this.Plugin = plugin;
this.Filter = null;
}
internal AddFilter(SoundFilterPlugin plugin, CustomFilter filter) {
internal AddFilter(Plugin plugin, CustomFilter filter) {
this.Plugin = plugin;
this.Filter = filter;

View File

@ -1,15 +1,14 @@
using System;
using System.Globalization;
using Dalamud.Logging;
using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class PluginUi : IDisposable {
private SoundFilterPlugin Plugin { get; }
private Plugin Plugin { get; }
internal Settings Settings { get; }
private SoundLog SoundLog { get; }
internal PluginUi(SoundFilterPlugin plugin) {
internal PluginUi(Plugin plugin) {
this.Plugin = plugin;
this.ConfigureLanguage();
@ -34,7 +33,7 @@ namespace SoundFilter.Ui {
try {
Language.Culture = new CultureInfo(langCode);
} 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;
}
}

View File

@ -6,14 +6,14 @@ using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class Settings : IDisposable {
private SoundFilterPlugin Plugin { get; }
private Plugin Plugin { get; }
private AddFilter AddFilter { get; }
private AddFilter? EditFilter { get; set; }
private bool _showWindow;
private int _dragging = -1;
internal Settings(SoundFilterPlugin plugin) {
internal Settings(Plugin 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, this.Plugin.Name);
var windowTitle = string.Format(Language.SettingsWindowTitle, Plugin.Name);
if (!ImGui.Begin($"{windowTitle}###soundfilter-settings", ref this._showWindow)) {
ImGui.End();
return;

View File

@ -7,11 +7,11 @@ using SoundFilter.Resources;
namespace SoundFilter.Ui {
public class SoundLog {
private SoundFilterPlugin Plugin { get; }
private Plugin Plugin { get; }
private string _search = string.Empty;
internal SoundLog(SoundFilterPlugin plugin) {
internal SoundLog(Plugin plugin) {
this.Plugin = plugin;
}