From 040de20bc447f7fda14dbba6c9082ddc8f48d720 Mon Sep 17 00:00:00 2001 From: Lilith Song Date: Mon, 22 Jul 2024 14:12:07 -0400 Subject: [PATCH] Hotfix /playsound hard-crashing the game Closes #13 by removing the old signature-based hook to play chat sounds and replacing it with ClientStructs. --- TinyCmds/Commands/PlayChatSound.cs | 10 ++++------ TinyCmds/Internal/PlaySound.cs | 20 -------------------- TinyCmds/Plugin.cs | 2 -- TinyCmds/TinyCmds.csproj | 2 +- 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 TinyCmds/Internal/PlaySound.cs diff --git a/TinyCmds/Commands/PlayChatSound.cs b/TinyCmds/Commands/PlayChatSound.cs index 093879e..5b458c7 100644 --- a/TinyCmds/Commands/PlayChatSound.cs +++ b/TinyCmds/Commands/PlayChatSound.cs @@ -1,3 +1,5 @@ +using FFXIVClientStructs.FFXIV.Client.UI; + using PrincessRTFM.TinyCmds.Attributes; using PrincessRTFM.TinyCmds.Chat; using PrincessRTFM.TinyCmds.Utils; @@ -11,11 +13,7 @@ namespace PrincessRTFM.TinyCmds.Commands; )] public class PlayChatSound: PluginCommand { protected override void Execute(string? command, string rawArguments, FlagMap flags, bool verbose, bool dryRun, ref bool showHelp) { - if (!Plugin.Sfx.Valid) { - ChatUtil.ShowPrefixedError("Unable to play sounds, the relevant game function couldn't be located"); - return; - } - if (!int.TryParse(rawArguments, out int idx)) { + if (!uint.TryParse(rawArguments, out uint idx)) { ChatUtil.ShowPrefixedError("Invalid value, must provide a sound ID from 1-16, inclusive"); return; } @@ -23,6 +21,6 @@ protected override void Execute(string? command, string rawArguments, FlagMap fl ChatUtil.ShowPrefixedError("Invalid sound ID, must be 1-16 inclusive"); return; } - Plugin.Sfx.Play(SoundsExtensions.FromGameIndex(idx)); + UIModule.PlayChatSoundEffect(idx); } } diff --git a/TinyCmds/Internal/PlaySound.cs b/TinyCmds/Internal/PlaySound.cs deleted file mode 100644 index c150077..0000000 --- a/TinyCmds/Internal/PlaySound.cs +++ /dev/null @@ -1,20 +0,0 @@ -using PrincessRTFM.TinyCmds.Utils; - -namespace PrincessRTFM.TinyCmds.Internal; - -internal delegate ulong PlaySoundDelegate(int soundId, ulong unknown1, ulong unknown2); -internal class PlaySound: GameFunctionBase { - internal PlaySound() : base("E8 ?? ?? ?? ?? 4D 39 BE") { } - internal void Play(Sound sound) { - if (this.Valid && sound.IsSound()) { - Logger.Verbose($"Playing sound {sound.ToSoundName()}"); - this.Invoke((int)sound, 0ul, 0ul); - } - else if (this.Valid) { - Logger.Warning($"Something tried to play an invalid sound effect"); - } - else { - Logger.Warning("Unable to play sounds, game function couldn't be located"); - } - } -} diff --git a/TinyCmds/Plugin.cs b/TinyCmds/Plugin.cs index 73d341f..04effbf 100644 --- a/TinyCmds/Plugin.cs +++ b/TinyCmds/Plugin.cs @@ -47,7 +47,6 @@ public class Plugin: IDalamudPlugin { [PluginService] internal static IPluginLog Log { get; private set; } = null!; [PluginService] internal static IGameInteropProvider Interop { get; private set; } = null!; internal static PluginCommandManager CommandManager { get; private set; } = null!; - internal static PlaySound Sfx { get; private set; } = null!; internal static XivCommonBase Common { get; private set; } = null!; internal static ServerChat ServerChat { get; private set; } = null!; @@ -59,7 +58,6 @@ public Plugin() { //ServerChat = Common.Functions.Chat; // XivCommon isn't updated yet, so we're ripping the chat functionality locally ServerChat = new(Scanner); - Sfx = new(); CommandManager = new(this) { ErrorHandler = ChatUtil.ShowPrefixedError }; diff --git a/TinyCmds/TinyCmds.csproj b/TinyCmds/TinyCmds.csproj index 7aec23c..56ac143 100644 --- a/TinyCmds/TinyCmds.csproj +++ b/TinyCmds/TinyCmds.csproj @@ -2,7 +2,7 @@ TinyCmds - 8.9.0 + 8.9.1 This plugin adds tiny and simple but useful chat commands, and nothing more. It finally has a UI specifically for command help. https://github.com/PrincessRTFM/TinyCommands Copyleft VariableVixen 2021