diff --git a/IgnoreMessages.csproj b/IgnoreMessages.csproj
index 14d3c54..f91498a 100644
--- a/IgnoreMessages.csproj
+++ b/IgnoreMessages.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/Plugin/Plugin.cs b/Plugin/Plugin.cs
index 046eb46..eb8a070 100644
--- a/Plugin/Plugin.cs
+++ b/Plugin/Plugin.cs
@@ -3,7 +3,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
- [MinimumApiVersion(315)]
+ [MinimumApiVersion(340)]
public sealed partial class Plugin : BasePlugin, IPluginConfig
{
public required PluginConfig Config { get; set; } = new PluginConfig();
diff --git a/Plugin/PluginManifest.cs b/Plugin/PluginManifest.cs
index 0bd9d08..e62199a 100644
--- a/Plugin/PluginManifest.cs
+++ b/Plugin/PluginManifest.cs
@@ -10,7 +10,7 @@ public sealed partial class Plugin : BasePlugin
public override string ModuleAuthor => "Nexd @ Eternar (https://eternar.dev)";
- public override string ModuleVersion => "1.0.4 " +
+ public override string ModuleVersion => "1.0.5 " +
#if RELEASE
"(release)";
#else
diff --git a/Services/IgnoreMessage.cs b/Services/IgnoreMessage.cs
index b88aa15..6be3cde 100644
--- a/Services/IgnoreMessage.cs
+++ b/Services/IgnoreMessage.cs
@@ -4,6 +4,31 @@
using CounterStrikeSharp.API.Core.Plugin;
using CounterStrikeSharp.API.Modules.UserMessages;
+ public enum TargetedMessages : int
+ {
+ UM_HudMsg = 110,
+ UM_HudText = 111,
+
+ UM_SayText = 117,
+ UM_SayText2 = 118,
+ UM_SayTextChannel = 119,
+
+ UM_TextMsg = 124,
+
+ CS_UM_HudText = 304,
+
+ CS_UM_SayText = 305,
+ CS_UM_SayText2 = 306,
+
+ CS_UM_TextMsg = 307,
+
+ CS_UM_HudMsg = 308,
+
+ CS_UM_RadioText = 322,
+ CS_UM_HintText = 323,
+ CS_UM_KeyHintText = 324
+ }
+
public class IgnoreMessage
{
private readonly ILogger Logger;
@@ -12,6 +37,8 @@ public class IgnoreMessage
public required Plugin Plugin;
+ private readonly Array Messages = Enum.GetValues(typeof(TargetedMessages));
+
public IgnoreMessage(ILogger logger, IPluginContext pluginContext)
{
this.Logger = logger;
@@ -22,49 +49,110 @@ public void Initialize(bool hotReload)
{
this.Plugin = (this.PluginContext.Plugin as Plugin)!;
- this.Plugin.HookUserMessage(124, OnMessagePrint, HookMode.Pre);
- this.Plugin.HookUserMessage(323, OnHudMessage, HookMode.Pre);
+ foreach (TargetedMessages messageId in this.Messages)
+ {
+#if DEBUG
+ this.Logger.LogInformation("Hooking UserMessage '{0}' ({1})", messageId, (int)messageId);
+#endif
+
+ // Process terminated.
+ // A callback was made on a garbage collected delegate of type 'CounterStrikeSharp.API!CounterStrikeSharp.API.Core.FunctionReference+CallbackDelegate::Invoke'.
+ this.Plugin.HookUserMessage((int)messageId, this.OnUserMessage, HookMode.Pre);
+ }
}
- private HookResult OnHudMessage(UserMessage message)
+ private HookResult HandleMessage(string messageName, string locToken)
{
- string msg = message.ReadString("message");
+ if (!locToken.StartsWith("#"))
+ {
+ return HookResult.Continue;
+ }
- if (msg.StartsWith("#"))
+ if (this.Plugin.Config.IgnoredMessages.Contains(locToken))
{
- if (this.Plugin.Config.IgnoredMessages.Contains(msg))
- {
- return HookResult.Stop;
- }
+ return HookResult.Stop;
+ }
- if (this.Plugin.Config.PrintKeyNames)
- {
- this.Logger.LogInformation("Current message key: \"{0}\"", msg.Replace(Environment.NewLine, string.Empty));
- }
+ if (this.Plugin.Config.PrintKeyNames)
+ {
+ this.Logger.LogInformation("Current message key: \"{0}\" ({1})", locToken.Replace(Environment.NewLine, string.Empty), messageName);
}
return HookResult.Continue;
}
- private HookResult OnMessagePrint(UserMessage message)
+ private HookResult OnUserMessage(UserMessage message)
{
- int count = message.GetRepeatedFieldCount("param");
+#if DEBUG
+ this.Logger.LogInformation("{0}", message.Name);
+#endif
- for(int i = 0; i < count; i++)
+ TargetedMessages messageId = (TargetedMessages)message.Id;
+
+ switch (messageId)
{
- string msg = message.ReadString("param", i);
+ case TargetedMessages.UM_HudMsg:
+ case TargetedMessages.UM_HudText:
+
+ case TargetedMessages.CS_UM_HintText:
+ return this.SingleParam(message, "message");
+
+ case TargetedMessages.UM_SayText:
+ case TargetedMessages.UM_SayTextChannel:
- if (msg.StartsWith("#"))
+ case TargetedMessages.CS_UM_HudText:
+ case TargetedMessages.CS_UM_SayText:
+ case TargetedMessages.CS_UM_HudMsg:
+ return this.SingleParam(message, "text");
+
+ case TargetedMessages.UM_SayText2:
+
+ case TargetedMessages.CS_UM_SayText2: // NEED REVISION: this one is only assumed yet
+ return this.SingleParam(message, "messagename");
+
+ case TargetedMessages.UM_TextMsg:
+
+ case TargetedMessages.CS_UM_TextMsg: // NEED REVISION: this one is only assumed yet
+ return this.MultipleParam(message, "param");
+
+ case TargetedMessages.CS_UM_KeyHintText:
+ return this.MultipleParam(message, "messages");
+
+ case TargetedMessages.CS_UM_RadioText:
{
- if (this.Plugin.Config.IgnoredMessages.Contains(msg))
+ // this handles tokens like `#Game_radio_location`
+ if (this.SingleParam(message, "msg_name") != HookResult.Continue)
{
return HookResult.Stop;
}
- if (this.Plugin.Config.PrintKeyNames)
- {
- this.Logger.LogInformation("Current message key: \"{0}\"", msg.Replace(Environment.NewLine, string.Empty));
- }
+ // this handles tokens like `#Cstrike_TitlesTXT_Roger_that`
+ return this.MultipleParam(message, "params");
+ }
+
+ default:
+ break;
+ }
+
+ return HookResult.Continue;
+ }
+
+ private HookResult SingleParam(UserMessage message, string paramName)
+ {
+ return this.HandleMessage(message.Name, message.ReadString(paramName));
+ }
+
+ private HookResult MultipleParam(UserMessage message, string paramName)
+ {
+ int count = message.GetRepeatedFieldCount(paramName);
+
+ for(int i = 0; i < count; i++)
+ {
+ HookResult result = this.HandleMessage(message.Name, message.ReadString(paramName, i));
+
+ if (result != HookResult.Continue)
+ {
+ return result;
}
}
@@ -73,8 +161,10 @@ private HookResult OnMessagePrint(UserMessage message)
public void Release(bool hotReload)
{
- this.Plugin.UnhookUserMessage(124, OnMessagePrint, HookMode.Pre);
- this.Plugin.UnhookUserMessage(323, OnHudMessage, HookMode.Pre);
+ foreach (TargetedMessages messageId in this.Messages)
+ {
+ this.Plugin.UnhookUserMessage((int)messageId, this.OnUserMessage, HookMode.Pre);
+ }
}
}
}