From af9d50266c319c4d4a0d1b8686189eb54ba5acd0 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sat, 25 Apr 2020 19:15:25 +0200 Subject: [PATCH 1/7] feat: add OnCheckChatMessageHandled, refactor ChatGui a bit --- Dalamud/Game/ChatHandlers.cs | 43 ++++++++++-------- Dalamud/Game/Command/CommandManager.cs | 8 ++-- Dalamud/Game/Internal/Gui/ChatGui.cs | 62 ++++++++++++++++++-------- 3 files changed, 72 insertions(+), 41 deletions(-) diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 3c2d59474..5a5d99c69 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -91,15 +91,38 @@ namespace Dalamud.Game { public ChatHandlers(Dalamud dalamud) { this.dalamud = dalamud; - + + dalamud.Framework.Gui.Chat.OnCheckMessageHandled += OnCheckMessageHandled; dalamud.Framework.Gui.Chat.OnChatMessageRaw += OnChatMessage; } + private void OnCheckMessageHandled(XivChatType type, uint senderid, ref SeString sender, ref SeString message, ref bool isHandled) { + var textVal = message.TextValue; + + var matched = this.rmtRegex.IsMatch(textVal); + if (matched) + { + // This seems to be a RMT ad - let's not show it + Log.Debug("Handled RMT ad: " + message.TextValue); + isHandled = true; + return; + } + + + if (this.dalamud.Configuration.BadWords != null && + this.dalamud.Configuration.BadWords.Any(x => textVal.Contains(x))) + { + // This seems to be in the user block list - let's not show it + Log.Debug("Blocklist triggered"); + isHandled = true; + return; + } + } public string LastLink { get; private set; } private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender, - ref StdString message, ref bool isHandled) { + ref StdString message, bool isHandled) { if (type == XivChatType.Notice && !this.hasSeenLoadingMsg) { var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); @@ -142,25 +165,9 @@ namespace Dalamud.Game { return; #endif - var matched = this.rmtRegex.IsMatch(message.Value); - if (matched) { - // This seems to be a RMT ad - let's not show it - Log.Debug("Handled RMT ad"); - isHandled = true; - return; - } - var messageVal = message.Value; var senderVal = sender.Value; - if (this.dalamud.Configuration.BadWords != null && - this.dalamud.Configuration.BadWords.Any(x => messageVal.Contains(x))) { - // This seems to be in the user block list - let's not show it - Log.Debug("Blocklist triggered"); - isHandled = true; - return; - } - if (type == XivChatType.RetainerSale) { foreach (var regex in retainerSaleRegexes[dalamud.StartInfo.Language]) diff --git a/Dalamud/Game/Command/CommandManager.cs b/Dalamud/Game/Command/CommandManager.cs index 98ca22642..794a0f93d 100644 --- a/Dalamud/Game/Command/CommandManager.cs +++ b/Dalamud/Game/Command/CommandManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text.RegularExpressions; using Dalamud.Game.Chat; +using Dalamud.Game.Chat.SeStringHandling; using Dalamud.Game.Internal.Libc; using Serilog; @@ -54,13 +55,12 @@ namespace Dalamud.Game.Command { break; } - dalamud.Framework.Gui.Chat.OnChatMessageRaw += OnChatMessage; + dalamud.Framework.Gui.Chat.OnCheckMessageHandled += OnCheckMessageHandled; } - private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender, - ref StdString message, ref bool isHandled) { + private void OnCheckMessageHandled(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) { if (type == XivChatType.ErrorMessage && senderId == 0) { - var cmdMatch = this.currentLangCommandRegex.Match(message.Value).Groups["command"]; + var cmdMatch = this.currentLangCommandRegex.Match(message.TextValue).Groups["command"]; if (cmdMatch.Success) { // Yes, it's a chat command. var command = cmdMatch.Value; diff --git a/Dalamud/Game/Internal/Gui/ChatGui.cs b/Dalamud/Game/Internal/Gui/ChatGui.cs index b1b94465a..14e919251 100644 --- a/Dalamud/Game/Internal/Gui/ChatGui.cs +++ b/Dalamud/Game/Internal/Gui/ChatGui.cs @@ -11,30 +11,52 @@ using Serilog; namespace Dalamud.Game.Internal.Gui { public sealed class ChatGui : IDisposable { + private readonly Queue chatQueue = new Queue(); + + #region Events + + public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, bool isHandled); + public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, bool isHandled); + public delegate void OnCheckMessageHandledDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); + + /// + /// Event that allows you to stop messages from appearing in chat by setting the isHandled parameter to true. + /// + public event OnCheckMessageHandledDelegate OnCheckMessageHandled; + + /// + /// Event that will be fired when a chat message is sent to chat by the game. + /// + public event OnMessageDelegate OnChatMessage; + + /// + /// Event that will be fired when a chat message is sent by the game, containing raw, unparsed data. + /// + [Obsolete("Please use OnChatMessage instead. For modifications, it will take precedence.")] + public event OnMessageRawDelegate OnChatMessageRaw; + + #endregion + + #region Hooks + + private readonly Hook printMessageHook; + + private readonly Hook populateItemLinkHook; + + #endregion + + #region Delegates + [UnmanagedFunctionPointer(CallingConvention.ThisCall)] private delegate IntPtr PrintMessageDelegate(IntPtr manager, XivChatType chatType, IntPtr senderName, - IntPtr message, - uint senderId, IntPtr parameter); - - public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, - ref bool isHandled); - - public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, - ref bool isHandled); + IntPtr message, + uint senderId, IntPtr parameter); [UnmanagedFunctionPointer(CallingConvention.ThisCall)] private delegate void PopulateItemLinkDelegate(IntPtr linkObjectPtr, IntPtr itemInfoPtr); - private readonly Queue chatQueue = new Queue(); - - private readonly Hook printMessageHook; - - public event OnMessageDelegate OnChatMessage; - [Obsolete("Please use OnChatMessage instead. For modifications, it will take precedence.")] - public event OnMessageRawDelegate OnChatMessageRaw; - - private readonly Hook populateItemLinkHook; + #endregion public int LastLinkedItemId { get; private set; } public byte LastLinkedItemFlags { get; private set; } @@ -106,8 +128,10 @@ namespace Dalamud.Game.Internal.Gui { // Call events var isHandled = false; - OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); - OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled); + OnCheckMessageHandled?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); + + OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, isHandled); + OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, isHandled); var newEdited = parsedMessage.Encode(); From b8b05ae998c8f918b2e253ff6e64cbcf6b6a4481 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 15:15:50 +0200 Subject: [PATCH 2/7] fix: don't load ChatExtender if it's <1400 (hack, remove this some time) --- Dalamud/Plugin/PluginManager.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Dalamud/Plugin/PluginManager.cs b/Dalamud/Plugin/PluginManager.cs index 56755bd53..3725658f8 100644 --- a/Dalamud/Plugin/PluginManager.cs +++ b/Dalamud/Plugin/PluginManager.cs @@ -100,6 +100,19 @@ namespace Dalamud.Plugin JsonConvert.DeserializeObject( File.ReadAllText(defJsonFile.FullName)); + // Don't wanna fuck this up + // This is a fix for earlier Chat Extender versions, since they break command handlers + try { + if (dllFile.Name.Contains("ChatExtender") && + int.Parse(pluginDef.AssemblyVersion.Replace(".", "")) < 1410) { + Log.Information("Found banned ChatExtender, skipping..."); + return false; + } + } catch (Exception) { + // ignored + } + + if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any") { Log.Information("Plugin {0} has not applicable version.", dllFile.FullName); From b9818c75a05051011f81dc8fdfbdace733c04867 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 15:18:15 +0200 Subject: [PATCH 3/7] fix: restore ref IsHandled for the Chat hooks --- Dalamud/Game/ChatHandlers.cs | 2 +- Dalamud/Game/Internal/Gui/ChatGui.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 5a5d99c69..1aabc893a 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -122,7 +122,7 @@ namespace Dalamud.Game { public string LastLink { get; private set; } private void OnChatMessage(XivChatType type, uint senderId, ref StdString sender, - ref StdString message, bool isHandled) { + ref StdString message, ref bool isHandled) { if (type == XivChatType.Notice && !this.hasSeenLoadingMsg) { var assemblyVersion = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); diff --git a/Dalamud/Game/Internal/Gui/ChatGui.cs b/Dalamud/Game/Internal/Gui/ChatGui.cs index 14e919251..d43bae8c8 100644 --- a/Dalamud/Game/Internal/Gui/ChatGui.cs +++ b/Dalamud/Game/Internal/Gui/ChatGui.cs @@ -15,8 +15,8 @@ namespace Dalamud.Game.Internal.Gui { #region Events - public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, bool isHandled); - public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, bool isHandled); + public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); + public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, ref bool isHandled); public delegate void OnCheckMessageHandledDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); /// @@ -130,8 +130,8 @@ namespace Dalamud.Game.Internal.Gui { var isHandled = false; OnCheckMessageHandled?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); - OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, isHandled); - OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, isHandled); + OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); + OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled); var newEdited = parsedMessage.Encode(); From 74e95d99fad987c6a0988bd1a411cefc28de733c Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 15:21:47 +0200 Subject: [PATCH 4/7] build: v4.9.0.0 --- Dalamud.Injector/Dalamud.Injector.csproj | 6 +++--- Dalamud/Dalamud.csproj | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dalamud.Injector/Dalamud.Injector.csproj b/Dalamud.Injector/Dalamud.Injector.csproj index 2788d54fc..1f4479024 100644 --- a/Dalamud.Injector/Dalamud.Injector.csproj +++ b/Dalamud.Injector/Dalamud.Injector.csproj @@ -14,10 +14,10 @@ true - 4.8.9.0 - 4.8.9.0 + 4.9.0.0 + 4.9.0.0 XIVLauncher addon injection - 4.8.9.0 + 4.9.0.0 diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index 8207b6386..77cdbf446 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -14,9 +14,9 @@ true - 4.8.9.0 - 4.8.9.0 - 4.8.9.0 + 4.9.0.0 + 4.9.0.0 + 4.9.0.0 From 9b591e71d2376bedd870563363d62dbcffacaa7c Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 15:25:16 +0200 Subject: [PATCH 5/7] fix: handle errors during EnsureAssets --- Dalamud/Dalamud.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 12cad078d..26fd2b73b 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -22,6 +22,7 @@ using Dalamud.Game.Network; using Dalamud.Interface; using Dalamud.Plugin; using ImGuiNET; +using Lumina.Excel.GeneratedSheets; using Newtonsoft.Json; using Serilog; using Serilog.Core; @@ -92,6 +93,10 @@ namespace Dalamud { this.WinSock2 = new WinSockHandlers(); AssetManager.EnsureAssets(this.baseDirectory).ContinueWith(async task => { + if (task.IsCanceled || task.IsFaulted) { + throw new Exception("Could not ensure assets.", task.Exception); + } + this.localizationMgr = new Localization(this.StartInfo.WorkingDirectory); if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) { this.localizationMgr.SetupWithLangCode(this.Configuration.LanguageOverride); From 62ef6034ee3cadb12f39f1493bbf9d095112a6f0 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 18:43:40 +0200 Subject: [PATCH 6/7] fix: work around bad assembly version in chat extender json --- Dalamud/Plugin/PluginManager.cs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Dalamud/Plugin/PluginManager.cs b/Dalamud/Plugin/PluginManager.cs index 3725658f8..2bf42e4f0 100644 --- a/Dalamud/Plugin/PluginManager.cs +++ b/Dalamud/Plugin/PluginManager.cs @@ -100,19 +100,6 @@ namespace Dalamud.Plugin JsonConvert.DeserializeObject( File.ReadAllText(defJsonFile.FullName)); - // Don't wanna fuck this up - // This is a fix for earlier Chat Extender versions, since they break command handlers - try { - if (dllFile.Name.Contains("ChatExtender") && - int.Parse(pluginDef.AssemblyVersion.Replace(".", "")) < 1410) { - Log.Information("Found banned ChatExtender, skipping..."); - return false; - } - } catch (Exception) { - // ignored - } - - if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any") { Log.Information("Plugin {0} has not applicable version.", dllFile.FullName); @@ -135,6 +122,23 @@ namespace Dalamud.Plugin // Assembly.Load() by name here will not load multiple versions with the same name, in the case of updates var pluginAssembly = Assembly.LoadFile(dllFile.FullName); + // Don't wanna fuck this up + // This is a fix for earlier Chat Extender versions, since they break command handlers + try + { + var ver = int.Parse(pluginAssembly.GetName().Version.ToString().Replace(".", "")); + if (dllFile.Name.Contains("ChatExtender") && + ver < 1410) + { + Log.Information($"Found banned v{ver} ChatExtender, skipping..."); + return false; + } + } + catch (Exception) + { + // ignored + } + if (pluginAssembly != null) { Log.Information("Loading types for {0}", pluginAssembly.FullName); From dee30b565587a79137f106845f12a5c846f7e342 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 26 Apr 2020 18:48:48 +0200 Subject: [PATCH 7/7] build: v4.9.1.0 --- Dalamud.Injector/Dalamud.Injector.csproj | 6 +++--- Dalamud/Dalamud.csproj | 11 +++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/Dalamud.Injector/Dalamud.Injector.csproj b/Dalamud.Injector/Dalamud.Injector.csproj index 1f4479024..e768c48f4 100644 --- a/Dalamud.Injector/Dalamud.Injector.csproj +++ b/Dalamud.Injector/Dalamud.Injector.csproj @@ -14,10 +14,10 @@ true - 4.9.0.0 - 4.9.0.0 + 4.9.1.0 + 4.9.1.0 XIVLauncher addon injection - 4.9.0.0 + 4.9.1.0 diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index 77cdbf446..609c1e89b 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -14,9 +14,9 @@ true - 4.9.0.0 - 4.9.0.0 - 4.9.0.0 + 4.9.1.0 + 4.9.1.0 + 4.9.1.0 @@ -76,9 +76,4 @@ - - - PreserveNewest - -