Skip to content

Commit

Permalink
Quick fixes (#185)
Browse files Browse the repository at this point in the history
* Only patch if ranks are enabled

* fix dumb

* Add catch for patch

* bring back motd

Co-authored-by: Bishbash777 <[email protected]>
  • Loading branch information
Bishbash777 and Bishbash777 authored Mar 17, 2021
1 parent 9f5ae7d commit b19b8d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Essentials/EssentialsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public EssentialsConfig()
public ObservableCollection<InfoCommand> InfoCommands { get; } = new ObservableCollection<InfoCommand>();

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;
Expand Down
5 changes: 4 additions & 1 deletion Essentials/Patches/ChatMessagePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b19b8d9

Please sign in to comment.