using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using HoldfastGame; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServerSilencer { [BepInPlugin("com.ryannlt.serversilencer", "ServerSilencer", "1.0.0")] public class ServerSilencerMod : BaseUnityPlugin { public const string Guid = "com.ryannlt.serversilencer"; internal static ConfigEntry BlockAdminChat; internal static ConfigEntry BlockNotifications; private DateTime _stamp; private float _nextCheck; private void Awake() { BlockAdminChat = ((BaseUnityPlugin)this).Config.Bind("General", "BlockAdminChat", true, "Hide chat lines the server posts on the admin channel. Private messages are never affected."); BlockNotifications = ((BaseUnityPlugin)this).Config.Bind("General", "BlockNotifications", false, "Also hide the centre-screen admin notification popups."); _stamp = Stamp(); Harmony.CreateAndPatchAll(typeof(ServerSilencerMod).Assembly, "com.ryannlt.serversilencer"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Ready. BlockAdminChat={BlockAdminChat.Value} BlockNotifications={BlockNotifications.Value}"); } private void Update() { if (!(Time.unscaledTime < _nextCheck)) { _nextCheck = Time.unscaledTime + 1f; DateTime dateTime = Stamp(); if (!(dateTime == _stamp)) { _stamp = dateTime; ((BaseUnityPlugin)this).Config.Reload(); } } } private DateTime Stamp() { try { return File.GetLastWriteTimeUtc(((BaseUnityPlugin)this).Config.ConfigFilePath); } catch (Exception) { return _stamp; } } } [HarmonyPatch(typeof(ClientChatHandler), "AddChatEntry", new Type[] { typeof(int), typeof(string), typeof(TextChatEntryType), typeof(TextChatChannel), typeof(string) })] internal static class ChatEntryPatch { private static bool Prefix(int playerID, TextChatEntryType entryType, TextChatChannel channel) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return !ShouldHide(playerID, entryType, channel); } private static bool ShouldHide(int playerID, TextChatEntryType entryType, TextChatChannel channel) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 if (!ServerSilencerMod.BlockAdminChat.Value) { return false; } if ((int)entryType == 4 || (int)entryType == 5) { return false; } return (int)entryType == 7 || ((int)channel == 12 && playerID == -1); } } [HarmonyPatch(typeof(AdminFancyUINotificationPanel), "ShowAdminNotification")] internal static class AdminNotificationPatch { private static bool Prefix(FancyNotificationType notificationType) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 if (!ServerSilencerMod.BlockNotifications.Value) { return true; } return (int)notificationType == 1; } } }