refactor: move to net5

This commit is contained in:
Anna 2021-08-24 14:18:09 -04:00
parent fcb0cdeedb
commit 04589e00a3
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
13 changed files with 198 additions and 74 deletions

View File

@ -12,13 +12,13 @@ namespace SoundFilter {
public Commands(SoundFilterPlugin plugin) {
this.Plugin = plugin;
this.Plugin.Interface.CommandManager.AddHandler(Name, new CommandInfo(this.OnCommand) {
HelpMessage = $"Toggle the {SoundFilterPlugin.Name} config",
this.Plugin.CommandManager.AddHandler(Name, new CommandInfo(this.OnCommand) {
HelpMessage = $"Toggle the {this.Plugin.Name} config",
});
}
public void Dispose() {
this.Plugin.Interface.CommandManager.RemoveHandler(Name);
this.Plugin.CommandManager.RemoveHandler(Name);
}
private void OnCommand(string command, string args) {
@ -27,13 +27,13 @@ namespace SoundFilter {
return;
}
var chat = this.Plugin.Interface.Framework.Gui.Chat;
var chat = this.Plugin.ChatGui;
var split = args.Split(' ');
if (split.Length < 1) {
chat.PrintError($"[{SoundFilterPlugin.Name}] {Language.CommandNotEnoughArguments}");
chat.PrintError($"[{SoundFilterPlugin.Name}] /soundfilter log");
chat.PrintError($"[{SoundFilterPlugin.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($"[{SoundFilterPlugin.Name}] {Language.CommandNoSuchFilter}");
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandNoSuchFilter}");
return;
}
@ -58,13 +58,22 @@ namespace SoundFilter {
_ => null,
};
if (enabled == null) {
chat.PrintError($"[{SoundFilterPlugin.Name}] {Language.CommandInvalidSubcommand}");
chat.PrintError($"[{this.Plugin.Name}] {Language.CommandInvalidSubcommand}");
return;
}
if (filter != null) {
filter.Enabled = enabled.Value;
} else {
switch (this.Plugin.Config.Enabled) {
case true when !enabled.Value:
this.Plugin.Filter.Disable();
break;
case false when enabled.Value:
this.Plugin.Filter.Enable();
break;
}
this.Plugin.Config.Enabled = enabled.Value;
}

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Dalamud.Plugin;
using Dalamud.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -22,9 +22,9 @@ namespace SoundFilter.Config {
private static void MigrateV1(JObject old) {
var filters = new List<CustomFilter>();
WithEachObject(old["Filtered"], (glob, filter) => {
var name = filter["Name"].Value<string>();
var enabled = filter["Enabled"].Value<bool>();
WithEachObject(old["Filtered"]!, (glob, filter) => {
var name = filter["Name"]!.Value<string>()!;
var enabled = filter["Enabled"]!.Value<bool>();
filters.Add(new CustomFilter {
Name = name,
Enabled = enabled,
@ -48,7 +48,7 @@ namespace SoundFilter.Config {
goto DefaultConfiguration;
}
var config = JsonConvert.DeserializeObject<JObject>(text);
var config = JsonConvert.DeserializeObject<JObject>(text)!;
int GetVersion() {
if (config.TryGetValue("Version", out var token)) {
@ -78,7 +78,7 @@ namespace SoundFilter.Config {
}
if (version == Configuration.LatestVersion) {
return config.ToObject<Configuration>();
return config.ToObject<Configuration>()!;
}
DefaultConfiguration:

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using Dalamud.Hooking;
using Dalamud.Plugin;
using Dalamud.Logging;
namespace SoundFilter {
internal unsafe class Filter : IDisposable {
@ -56,13 +56,13 @@ namespace SoundFilter {
private IntPtr MusicManager {
get {
if (!this.Plugin.Interface.TargetModuleScanner.TryScanText(Signatures.MusicManagerOffset, out var instructionPtr)) {
if (!this.Plugin.SigScanner.TryScanText(Signatures.MusicManagerOffset, out var instructionPtr)) {
PluginLog.LogWarning("Could not find music manager");
return IntPtr.Zero;
}
var offset = *(int*) (instructionPtr + 3);
return *(IntPtr*) (this.Plugin.Interface.Framework.Address.BaseAddress + offset);
return *(IntPtr*) (this.Plugin.Framework.Address.BaseAddress + offset);
}
}
@ -126,16 +126,16 @@ namespace SoundFilter {
}
internal void Enable() {
if (this.PlaySpecificSoundHook == null && this.Plugin.Interface.TargetModuleScanner.TryScanText(Signatures.PlaySpecificSound, out var playPtr)) {
this.PlaySpecificSoundHook = new Hook<PlaySpecificSoundDelegate>(playPtr, new PlaySpecificSoundDelegate(this.PlaySpecificSoundDetour));
if (this.PlaySpecificSoundHook == null && this.Plugin.SigScanner.TryScanText(Signatures.PlaySpecificSound, out var playPtr)) {
this.PlaySpecificSoundHook = new Hook<PlaySpecificSoundDelegate>(playPtr, this.PlaySpecificSoundDetour);
}
if (this.GetResourceSyncHook == null && this.Plugin.Interface.TargetModuleScanner.TryScanText(Signatures.GetResourceSync, out var syncPtr)) {
this.GetResourceSyncHook = new Hook<GetResourceSyncPrototype>(syncPtr, new GetResourceSyncPrototype(this.GetResourceSyncDetour));
if (this.GetResourceSyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceSync, out var syncPtr)) {
this.GetResourceSyncHook = new Hook<GetResourceSyncPrototype>(syncPtr, this.GetResourceSyncDetour);
}
if (this.GetResourceAsyncHook == null && this.Plugin.Interface.TargetModuleScanner.TryScanText(Signatures.GetResourceAsync, out var asyncPtr)) {
this.GetResourceAsyncHook = new Hook<GetResourceAsyncPrototype>(asyncPtr, new GetResourceAsyncPrototype(this.GetResourceAsyncDetour));
if (this.GetResourceAsyncHook == null && this.Plugin.SigScanner.TryScanText(Signatures.GetResourceAsync, out var asyncPtr)) {
this.GetResourceAsyncHook = new Hook<GetResourceAsyncPrototype>(asyncPtr, this.GetResourceAsyncDetour);
}
this.PlaySpecificSoundHook?.Enable();
@ -149,6 +149,20 @@ namespace SoundFilter {
this.GetResourceAsyncHook?.Disable();
}
internal void Toggle(bool save = true) {
if (this.Plugin.Config.Enabled) {
this.Disable();
} else {
this.Enable();
}
this.Plugin.Config.Enabled ^= true;
if (save) {
this.Plugin.Config.Save();
}
}
public void Dispose() {
this.PlaySpecificSoundHook?.Dispose();
this.GetResourceSyncHook?.Dispose();

View File

@ -1,5 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ResourcesMerge/>
<ILMerge/>
<Resourcer/>
</Weavers>

View File

@ -1,18 +0,0 @@
using Dalamud.Plugin;
namespace SoundFilter {
// ReSharper disable once UnusedType.Global
public class PluginShim : IDalamudPlugin {
public string Name => SoundFilterPlugin.Name;
private SoundFilterPlugin? Plugin { get; set; }
public void Initialize(DalamudPluginInterface pluginInterface) {
this.Plugin = new SoundFilterPlugin(pluginInterface);
}
public void Dispose() {
this.Plugin?.Dispose();
}
}
}

View File

@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net5-windows</TargetFramework>
<Version>1.4.2</Version>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
@ -39,11 +41,12 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
<PackageReference Include="DalamudPackager" Version="2.1.2"/>
<PackageReference Include="DotNet.Glob" Version="3.1.2"/>
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
<PackageReference Include="Fody" Version="6.5.2" PrivateAssets="all"/>
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
<PackageReference Include="ResourcesMerge.Fody" Version="1.0.3" PrivateAssets="all"/>
</ItemGroup>
<ItemGroup>
<Content Include="..\icon.png" Link="images/icon.png" CopyToOutputDirectory="PreserveNewest" Visible="false"/>
</ItemGroup>
</Project>

View File

@ -1,9 +1,13 @@
name: Sound Filter
author: ascclemens
punchline: Filter any game sound.
description: |-
Filters any sound or set of sounds from the game.
- Remove a battle sound effect you don't like
- Remove specific emote sounds
- Remove specific background music
Icons: filter by Kirby Wu from the Noun Project
and Sound by Gregor Cresnar from the Noun Project
repo_url: https://git.sr.ht/jkcclemens/SoundFilter

View File

@ -1,25 +1,41 @@
using System;
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 SoundFilter.Config;
using SoundFilter.Resources;
using SoundFilter.Ui;
namespace SoundFilter {
internal class SoundFilterPlugin : IDisposable {
internal const string Name = "Sound Filter";
// ReSharper disable once ClassNeverInstantiated.Global
internal class SoundFilterPlugin : IDalamudPlugin {
public string Name => "Sound Filter";
[PluginService]
internal DalamudPluginInterface Interface { get; init; } = null!;
[PluginService]
internal ChatGui ChatGui { get; init; } = null!;
[PluginService]
internal CommandManager CommandManager { get; init; } = null!;
[PluginService]
internal Framework Framework { get; init; } = null!;
[PluginService]
internal SigScanner SigScanner { get; init; } = null!;
internal DalamudPluginInterface Interface { get; }
internal Configuration Config { get; }
internal Filter Filter { get; }
internal PluginUi Ui { get; }
private Commands Commands { get; }
internal SoundFilterPlugin(DalamudPluginInterface @interface) {
this.Interface = @interface;
public SoundFilterPlugin() {
this.Config = Migrator.LoadConfiguration(this);
this.Config.Initialise(this.Interface);
@ -35,14 +51,14 @@ namespace SoundFilter {
return;
}
var message = string.Format(Language.LoadWarning, Name);
this.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
Name = Name,
MessageBytes = new SeString(new Payload[] {
new UIForegroundPayload(this.Interface.Data, 502),
new TextPayload($"[{Name}] {message}"),
new UIForegroundPayload(this.Interface.Data, 0),
}).Encode(),
var message = string.Format(Language.LoadWarning, this.Name);
this.ChatGui.PrintChat(new XivChatEntry {
Name = this.Name,
Message = new SeString(
new UIForegroundPayload(502),
new TextPayload($"[{this.Name}] {message}"),
new UIForegroundPayload(0)
),
});
}

View File

@ -1,6 +1,6 @@
using System;
using System.Globalization;
using Dalamud.Plugin;
using Dalamud.Logging;
using SoundFilter.Resources;
namespace SoundFilter.Ui {
@ -17,18 +17,19 @@ namespace SoundFilter.Ui {
this.Settings = new Settings(this.Plugin);
this.SoundLog = new SoundLog(this.Plugin);
this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw;
this.Plugin.Interface.OnLanguageChanged += this.ConfigureLanguage;
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
this.Plugin.Interface.LanguageChanged += this.ConfigureLanguage;
}
public void Dispose() {
this.Plugin.Interface.OnLanguageChanged -= this.ConfigureLanguage;
this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw;
this.Plugin.Interface.LanguageChanged -= this.ConfigureLanguage;
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
this.Settings.Dispose();
}
private void ConfigureLanguage(string? langCode = null) {
// ReSharper disable once ConstantNullCoalescingCondition
langCode ??= this.Plugin.Interface.UiLanguage ?? "en";
try {
Language.Culture = new CultureInfo(langCode);

View File

@ -17,14 +17,14 @@ namespace SoundFilter.Ui {
this.Plugin = plugin;
this.AddFilter = new AddFilter(plugin);
this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.Toggle;
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.Toggle;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.Toggle;
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.Toggle;
}
internal void Toggle(object? sender = null, object? args = null) {
internal void Toggle() {
this._showWindow = !this._showWindow;
}
@ -48,7 +48,7 @@ namespace SoundFilter.Ui {
ImGui.SetNextWindowSize(new Vector2(500, 450), ImGuiCond.FirstUseEver);
var windowTitle = string.Format(Language.SettingsWindowTitle, SoundFilterPlugin.Name);
var windowTitle = string.Format(Language.SettingsWindowTitle, this.Plugin.Name);
if (!ImGui.Begin($"{windowTitle}###soundfilter-settings", ref this._showWindow)) {
ImGui.End();
return;

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Dalamud.Game;
using Dalamud.Interface;

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

98
icon.svg Executable file
View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
data-name="Layer 1"
viewBox="0 0 100 100"
x="0px"
y="0px"
version="1.1"
id="svg10"
sodipodi:docname="icon.svg"
width="100"
height="100"
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
inkscape:export-filename="D:\code\SoundFilter\icon.png"
inkscape:export-xdpi="491.51999"
inkscape:export-ydpi="491.51999"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs14">
<linearGradient
inkscape:collect="always"
id="linearGradient930">
<stop
style="stop-color:#850000;stop-opacity:1"
offset="0"
id="stop926" />
<stop
style="stop-color:#003aaf;stop-opacity:1"
offset="1"
id="stop928" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient930"
id="linearGradient932"
x1="27.391356"
y1="26.969402"
x2="72.349539"
y2="26.969402"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.0549846,0,0,1.0549846,-2.6125575,-4.2766045)" />
</defs>
<sodipodi:namedview
id="namedview12"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:pageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
showgrid="false"
inkscape:zoom="6.656"
inkscape:cx="49.954928"
inkscape:cy="51.307091"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1592"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer2" />
<title
id="title2">Artboard 227</title>
<metadata
id="metadata831">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:title>Artboard 227</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Sound"
style="display:inline">
<path
d="m 71.738792,18.246787 h -1.976304 a 5.9289141,5.9289141 0 0 0 -5.928914,5.928915 v 7.905218 a 1.9763047,1.9763047 0 0 1 -3.952609,0 V 8.3652634 a 5.928915,5.928915 0 0 0 -11.85783,0 V 39.986139 a 1.9763047,1.9763047 0 0 1 -3.952608,0 V 16.270482 a 5.9289141,5.9289141 0 0 0 -11.857827,0 v 7.90522 a 1.9763047,1.9763047 0 0 1 -1.976307,1.976304 h -1.976302 a 1.9763047,1.9763047 0 0 0 0,3.952608 h 1.976302 a 5.9289141,5.9289141 0 0 0 5.928915,-5.928912 v -7.90522 a 1.9763047,1.9763047 0 0 1 3.952609,0 v 23.715657 a 5.9289147,5.9289147 0 0 0 11.857829,0 V 8.3652634 a 1.976305,1.976305 0 0 1 3.95261,0 V 32.08092 a 5.9289141,5.9289141 0 0 0 11.857827,0 v -7.905218 a 1.9763047,1.9763047 0 0 1 1.976305,-1.976305 h 1.976304 a 1.976305,1.976305 0 0 0 0,-3.95261 z"
id="path4"
style="fill:url(#linearGradient932);fill-opacity:1;stroke-width:0.494075" />
</g>
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="Filter">
<polygon
points="5.2,14.9 42.6,52.3 42.6,95 57.2,82.4 57.2,52.3 94.7,14.9 94.7,5 5.2,5 "
id="polygon2"
transform="matrix(0.74854882,0,0,0.74854882,12.609986,26.451514)"
style="fill:#858585;fill-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB