From b19b8d9441915c90d2dff978b636d6aaea62dddc Mon Sep 17 00:00:00 2001 From: Bishbash777 <50243964+Bishbash777@users.noreply.github.com> Date: Wed, 17 Mar 2021 13:18:34 +0000 Subject: [PATCH] Quick fixes (#185) * Only patch if ranks are enabled * fix dumb * Add catch for patch * bring back motd Co-authored-by: Bishbash777 --- Essentials/EssentialsConfig.cs | 1 + Essentials/Patches/ChatMessagePatch.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Essentials/EssentialsConfig.cs b/Essentials/EssentialsConfig.cs index 7514e24..7dae57c 100644 --- a/Essentials/EssentialsConfig.cs +++ b/Essentials/EssentialsConfig.cs @@ -34,6 +34,7 @@ public EssentialsConfig() public ObservableCollection InfoCommands { get; } = new ObservableCollection(); private string _motd; + [Display(Name = "Motd", Description = "Message displayed to players upon connection")] public string Motd { get => _motd; set => SetValue(ref _motd, value); } public bool _enableRanks = false; diff --git a/Essentials/Patches/ChatMessagePatch.cs b/Essentials/Patches/ChatMessagePatch.cs index b4eb2fa..2e9aa0b 100644 --- a/Essentials/Patches/ChatMessagePatch.cs +++ b/Essentials/Patches/ChatMessagePatch.cs @@ -34,13 +34,16 @@ public static MethodInfo FindOverLoadMethod( MethodInfo[] methodInfo,string name } public static void Patch(PatchContext ctx) { - if (EssentialsPlugin.Instance.Config.EnableRanks) { + try { var target = FindOverLoadMethod(typeof(MyMultiplayerBase).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static), "OnChatMessageReceived_Server", 1); var patchMethod = typeof(ChatMessagePatch).GetMethod(nameof(OnChatMessageReceived_Server), BindingFlags.Static | BindingFlags.NonPublic); ctx.GetPattern(target).Prefixes.Add(patchMethod); Log.Info("Patched OnChatMessageReceived_Server!"); } + catch { + Log.Error("Failed to patch!"); + } } private static bool OnChatMessageReceived_Server(ref ChatMsg msg) {