using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Localization.Components; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("GameAssembly")] [assembly: IgnoresAccessChecksTo("SharedAssembly")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ChaTweaks")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+37d9c6573317b5fad502fafbe6e7baad339fcf39")] [assembly: AssemblyProduct("ChaTweaks")] [assembly: AssemblyTitle("ChaTweaks")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Embedded] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace Microsoft.CodeAnalysis { [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace ChaTweaks { [HarmonyPatch] public class History { private static readonly List sent = new List(); private static readonly List saved = new List(); private static int recallIdx = -1; private static string? lastMsg; private static int currentMsgRepeat; private static readonly FieldInfo queue = AccessTools.Field(typeof(TextChatUi), "historyQueue"); private static readonly FieldInfo? newMsgQueue = AccessTools.Field(typeof(TextChatUi), "newMessagesQueue"); [HarmonyPatch(typeof(TextChatUi), "OnDestroy")] [HarmonyPrefix] private static void Save(TextChatUi __instance) { if (!Plugin.persistencyToggle.Value) { return; } saved.Clear(); Queue queue = (Queue)History.queue.GetValue(__instance); foreach (TextChatMessageUi item in queue) { TMP_Text componentInChildren = ((Component)item).GetComponentInChildren(); if ((Object)(object)componentInChildren != (Object)null) { saved.Add(componentInChildren.text); } } } [HarmonyPatch(typeof(TextChatUi), "Awake")] [HarmonyPostfix] private static void Restore() { if (!Plugin.persistencyToggle.Value || saved.Count == 0) { return; } foreach (string item in saved) { TextChatUi.ShowMessage(item); } saved.Clear(); } [HarmonyPatch(typeof(TextChatManager), "UserCode_CmdSendMessageInternal__String__NetworkConnectionToClient")] [HarmonyPrefix] private static void SaveSentMsgs(string message) { if (message.Length != 0) { sent.Remove(message); sent.Add(message); recallIdx = -1; } } [HarmonyPatch(typeof(TextChatUi), "Update")] [HarmonyPostfix] private static void Recall(TextChatUi __instance) { if (!TextChatUi.IsOpen || sent.Count == 0) { return; } Keyboard current = Keyboard.current; if (current != null && (((ButtonControl)current.upArrowKey).wasPressedThisFrame || ((ButtonControl)current.downArrowKey).wasPressedThisFrame)) { if (((ButtonControl)current.upArrowKey).wasPressedThisFrame) { recallIdx = Mathf.Clamp(recallIdx + 1, 0, sent.Count - 1); } else { recallIdx = Mathf.Clamp(recallIdx - 1, -1, sent.Count - 1); } __instance.messageField.text = ((recallIdx == -1) ? string.Empty : sent[sent.Count - 1 - recallIdx]); __instance.messageField.MoveToEndOfLine(false, false); } } [HarmonyPatch(typeof(TextChatUi), "ShowMessage")] [HarmonyPrefix] private static bool ShowMessage(string message) { if (!Plugin.scamCollapseToggle.Value || string.IsNullOrEmpty(message) || !SingletonBehaviour.HasInstance) { lastMsg = null; currentMsgRepeat = 0; return true; } if (message != lastMsg) { lastMsg = message; currentMsgRepeat = 1; return true; } UpdateLastMessage($"{message} (x{++currentMsgRepeat})"); return false; } private static void UpdateLastMessage(string text) { TextChatUi instance = SingletonBehaviour.Instance; SetQueueTail(instance, newMsgQueue, text); SetQueueTail(instance, queue, text); } private static void SetQueueTail(TextChatUi ui, FieldInfo? field, string text) { if (!(field?.GetValue(ui) is Queue { Count: not 0 } queue)) { return; } TextChatMessageUi val = null; foreach (TextChatMessageUi item in queue) { val = item; } if (!((Object)(object)val?.messageText == (Object)null)) { val.messageText.text = text; val.messageText.ForceMeshUpdate(false, false); } } } [BepInPlugin("ChaTweaks", "ChaTweaks", "1.0.0")] public class Plugin : BaseUnityPlugin { private Harmony harmony; internal static ConfigEntry persistencyToggle; internal static ConfigEntry profanityFilterToggle; internal static ConfigEntry scamCollapseToggle; public const string Id = "ChaTweaks"; internal static ManualLogSource Log { get; private set; } public static string Name => "ChaTweaks"; public static string Version => "1.0.0"; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Log = ((BaseUnityPlugin)this).Logger; persistencyToggle = ((BaseUnityPlugin)this).Config.Bind("ChaTweaks", "Persistent Text Chat", true, "Allow text chat messages to persist"); profanityFilterToggle = ((BaseUnityPlugin)this).Config.Bind("ChaTweaks", "Profanity Filter", true, "Toggle the text profanity filter (Other players need this off to SEND messages without the profanity filter)"); scamCollapseToggle = ((BaseUnityPlugin)this).Config.Bind("ChaTweaks", "Spam Collapse", true, "Repeated messages from the same sender will be collapsed"); Log.LogInfo((object)("Mod " + Name + " loaded!")); harmony.PatchAll(); } } [HarmonyPatch] public class ProfanityFilter { [HarmonyPatch(typeof(GameManager), "FilterProfanity")] [HarmonyPrefix] internal static bool Prefix(string verifyString, ref string filteredString, ref bool __result) { if (Plugin.profanityFilterToggle.Value) { return true; } filteredString = verifyString; __result = false; return false; } } [HarmonyPatch] public static class IngameSettings { private static readonly List boolSetting = new List(2) { "On", "Off" }; private static readonly ConfigEntry[] Toggleables = new ConfigEntry[3] { Plugin.persistencyToggle, Plugin.profanityFilterToggle, Plugin.scamCollapseToggle }; [HarmonyPatch(typeof(SettingsMenu), "Start")] [HarmonyPostfix] private static void Inject(SettingsMenu __instance) { DropdownOption muteChat = __instance.muteChat; if (!((Object)(object)muteChat == (Object)null)) { ConfigEntry[] toggleables = Toggleables; foreach (ConfigEntry setting in toggleables) { AddToggleThing(muteChat, ((Component)muteChat).transform.parent, __instance.generalTooltip, setting); } } } private static void AddToggleThing(DropdownOption template, Transform parent, UiTooltip tooltip, ConfigEntry setting) { Component val = (Component)(object)Object.Instantiate(template, parent); ((Object)val).name = "CT_" + ((ConfigEntryBase)setting).Definition.Key; LocalizeStringEvent[] componentsInChildren = val.GetComponentsInChildren(true); foreach (LocalizeStringEvent val2 in componentsInChildren) { ((Behaviour)val2).enabled = false; } DropdownOption dropdown = val.GetComponent(); if ((Object)(object)dropdown == (Object)null) { return; } dropdown.SetOptions(boolSetting); dropdown.Initialize((Action)delegate { setting.Value = dropdown.value == 0; }, (!setting.Value) ? 1 : 0); TMP_Text[] componentsInChildren2 = val.GetComponentsInChildren(true); foreach (TMP_Text val3 in componentsInChildren2) { if (!((Object)(object)((Component)val3).GetComponentInParent() != (Object)null)) { val3.text = ((ConfigEntryBase)setting).Definition.Key; val3.ForceMeshUpdate(false, false); break; } } tooltip.RegisterTooltip(val.GetComponent(), ((ConfigEntryBase)setting).Description.Description, (string)null); } } [HarmonyPatch] internal static class UIPatches { [HarmonyPatch(typeof(UiVisibilityController), "OnUiVisibilityModeChanged")] [HarmonyPostfix] private static void UIVisibilityChange(UiVisibilityController __instance) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance == (Object)null) && IsChatController(__instance) && (GameManager.HiddenUiGroups & 0x38) != 0) { ForceRender(__instance); } } [HarmonyPatch(typeof(TextChatUi), "SetEnabledInternal")] [HarmonyPostfix] private static void Enabled(TextChatUi __instance, bool enabled) { if (enabled && !((Object)(object)__instance == (Object)null)) { BringToTop(((Component)__instance).transform); } } [HarmonyPatch(typeof(Scoreboard), "UpdateVisibility")] [HarmonyPostfix] private static void BoardVisibilityChange() { TextChatUi val = (SingletonBehaviour.HasInstance ? SingletonBehaviour.Instance : Object.FindFirstObjectByType()); if ((Object)(object)val != (Object)null) { BringToTop(((Component)val).transform); } } private static bool IsChatController(UiVisibilityController controller) { if (!((Object)(object)((Component)controller).GetComponent() != (Object)null) && !((Object)(object)((Component)controller).GetComponentInParent() != (Object)null)) { return (Object)(object)((Component)controller).GetComponentInChildren(true) != (Object)null; } return true; } private static void ForceRender(UiVisibilityController controller) { Canvas val = default(Canvas); if (((Component)controller).TryGetComponent(ref val)) { ((Behaviour)val).enabled = true; } CanvasGroup component = ((Component)controller).GetComponent(); if ((Object)(object)component != (Object)null) { component.alpha = 1f; component.interactable = true; component.blocksRaycasts = true; } } private static void BringToTop(Transform root) { root.SetAsLastSibling(); Canvas[] componentsInChildren = ((Component)root).GetComponentsInChildren(true); foreach (Canvas val in componentsInChildren) { val.overrideSorting = true; val.sortingOrder = 20; } } } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ConstantExpectedAttribute : Attribute { public object? Min { get; set; } public object? Max { get; set; } } [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ExperimentalAttribute : Attribute { public string DiagnosticId { get; } public string? UrlFormat { get; set; } public ExperimentalAttribute(string diagnosticId) { DiagnosticId = diagnosticId; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] internal sealed class MemberNotNullAttribute : Attribute { public string[] Members { get; } public MemberNotNullAttribute(string member) { Members = new string[1] { member }; } public MemberNotNullAttribute(params string[] members) { Members = members; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] internal sealed class MemberNotNullWhenAttribute : Attribute { public bool ReturnValue { get; } public string[] Members { get; } public MemberNotNullWhenAttribute(bool returnValue, string member) { ReturnValue = returnValue; Members = new string[1] { member }; } public MemberNotNullWhenAttribute(bool returnValue, params string[] members) { ReturnValue = returnValue; Members = members; } } [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class SetsRequiredMembersAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class StringSyntaxAttribute : Attribute { public const string CompositeFormat = "CompositeFormat"; public const string DateOnlyFormat = "DateOnlyFormat"; public const string DateTimeFormat = "DateTimeFormat"; public const string EnumFormat = "EnumFormat"; public const string GuidFormat = "GuidFormat"; public const string Json = "Json"; public const string NumericFormat = "NumericFormat"; public const string Regex = "Regex"; public const string TimeOnlyFormat = "TimeOnlyFormat"; public const string TimeSpanFormat = "TimeSpanFormat"; public const string Uri = "Uri"; public const string Xml = "Xml"; public string Syntax { get; } public object?[] Arguments { get; } public StringSyntaxAttribute(string syntax) { Syntax = syntax; Arguments = new object[0]; } public StringSyntaxAttribute(string syntax, params object?[] arguments) { Syntax = syntax; Arguments = arguments; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class UnscopedRefAttribute : Attribute { } } namespace System.Runtime.Versioning { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class RequiresPreviewFeaturesAttribute : Attribute { public string? Message { get; } public string? Url { get; set; } public RequiresPreviewFeaturesAttribute() { } public RequiresPreviewFeaturesAttribute(string? message) { Message = message; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CallerArgumentExpressionAttribute : Attribute { public string ParameterName { get; } public CallerArgumentExpressionAttribute(string parameterName) { ParameterName = parameterName; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CollectionBuilderAttribute : Attribute { public Type BuilderType { get; } public string MethodName { get; } public CollectionBuilderAttribute(Type builderType, string methodName) { BuilderType = builderType; MethodName = methodName; } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CompilerFeatureRequiredAttribute : Attribute { public const string RefStructs = "RefStructs"; public const string RequiredMembers = "RequiredMembers"; public string FeatureName { get; } public bool IsOptional { get; set; } public CompilerFeatureRequiredAttribute(string featureName) { FeatureName = featureName; } } [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute { public string[] Arguments { get; } public InterpolatedStringHandlerArgumentAttribute(string argument) { Arguments = new string[1] { argument }; } public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) { Arguments = arguments; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class InterpolatedStringHandlerAttribute : Attribute { } [EditorBrowsable(EditorBrowsableState.Never)] [ExcludeFromCodeCoverage] internal static class IsExternalInit { } [AttributeUsage(AttributeTargets.Method, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ModuleInitializerAttribute : Attribute { } [AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class OverloadResolutionPriorityAttribute : Attribute { public int Priority { get; } public OverloadResolutionPriorityAttribute(int priority) { Priority = priority; } } [AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)] [ExcludeFromCodeCoverage] internal sealed class ParamCollectionAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class RequiredMemberAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [EditorBrowsable(EditorBrowsableState.Never)] [ExcludeFromCodeCoverage] internal sealed class RequiresLocationAttribute : Attribute { } [AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class SkipLocalsInitAttribute : Attribute { } }