Decompiled source of SignalTranslatorUpgrade v1.0.0

SignalTranslatorUpgrade.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.Linq;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SignalTranslatorUpgrade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fit more characters into transmissions!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7da60c7d33bc262e861d680200695ce99d57357b")]
[assembly: AssemblyProduct("SignalTranslatorUpgrade")]
[assembly: AssemblyTitle("SignalTranslatorUpgrade")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SignalTranslatorUpgrade
{
	[BepInPlugin("Fredolx.SignalTranslatorUpgrade", "SignalTranslatorUpgrade", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		public static string TransmitMessage { get; set; }

		public static string ClientMessage { get; set; }

		public static ConfigEntry<int> MaxCharacters { get; set; }

		private void Awake()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (Logger == null)
			{
				Logger = ((BaseUnityPlugin)this).Logger;
			}
			Logger.LogInfo((object)"Plugin SignalTranslatorUpgrade is loaded!");
			MaxCharacters = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxMessageLength", 30, "The maximum of characters that should be displayed on the screen when transmitting messages");
			new Harmony("SignalTranslatorUpgrade").PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SignalTranslatorUpgrade";

		public const string PLUGIN_NAME = "SignalTranslatorUpgrade";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SignalTranslatorUpgrade.Patches
{
	[HarmonyPatch(typeof(HUDManager), "UseSignalTranslatorServerRpc")]
	public class UseSignalTranslatorServerRpc
	{
		private static void Postfix(HUDManager __instance, string signalMessage)
		{
			if (signalMessage.Length > 12)
			{
				SignalTranslator val = Object.FindObjectOfType<SignalTranslator>();
				if (!(Time.realtimeSinceStartup - val.timeLastUsingSignalTranslator < 8f))
				{
					val.timeLastUsingSignalTranslator = Time.realtimeSinceStartup;
					val.timesSendingMessage++;
					__instance.UseSignalTranslatorClientRpc(signalMessage, val.timesSendingMessage);
					Plugin.Logger.LogInfo((object)("ServerRPC Postfix: " + signalMessage));
				}
			}
		}

		private static void Prefix(ref string signalMessage, HUDManager __instance)
		{
			if (Plugin.TransmitMessage != null)
			{
				signalMessage = Plugin.TransmitMessage;
				Plugin.Logger.LogInfo((object)("ServerRPC Prefix: " + signalMessage));
				Plugin.TransmitMessage = null;
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager), "UseSignalTranslatorClientRpc")]
	public class UseSignalTranslatorClientRpc
	{
		private static void Prefix(string signalMessage)
		{
			Plugin.Logger.LogInfo((object)("Client RPC Prefix: " + signalMessage));
			Plugin.ClientMessage = signalMessage;
		}
	}
	[HarmonyPatch(typeof(HUDManager), "DisplaySignalTranslatorMessage")]
	public class DisplaySignalTranslatorMessage
	{
		private static void Prefix(ref string signalMessage)
		{
			signalMessage = ((Plugin.ClientMessage.Length < Plugin.MaxCharacters.Value) ? Plugin.ClientMessage : Plugin.ClientMessage.Substring(0, Plugin.MaxCharacters.Value));
			Plugin.Logger.LogInfo((object)("Display: " + signalMessage));
			Plugin.ClientMessage = null;
		}
	}
	[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
	public class ParsePlayerSentence
	{
		private static bool Prefix(Terminal __instance)
		{
			string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
			text = Traverse.Create((object)__instance).Method("RemovePunctuation", new object[1] { text }).GetValue<string>();
			string[] array = text.Split(" ");
			if (array[0] != "transmit")
			{
				return true;
			}
			Plugin.TransmitMessage = string.Join(" ", array.Skip(1));
			return true;
		}
	}
}