Decompiled source of LCTerminalMultiCodes v1.0.0

LCTerminalMultiCodes.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LCTerminalMultiCodes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Makes the terminal support entering multiple codes at once.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cbacea52ed3180664230d27eca775bd3cbffefa0")]
[assembly: AssemblyProduct("LCTerminalMultiCodes")]
[assembly: AssemblyTitle("LCTerminalMultiCodes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LCTerminalMultiCodes
{
	[BepInPlugin("LCTerminalMultiCodes", "LCTerminalMultiCodes", "1.0.0")]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = null;

		internal static ManualLogSource Logger { get; private set; }

		protected Plugin()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("LCTerminalMultiCodes");
		}

		protected void Awake()
		{
			ManualLogSource logger = Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"Plugin LCTerminalMultiCodes is loaded!");
			}
			ManualLogSource logger2 = Logger;
			if (logger2 != null)
			{
				logger2.LogDebug((object)"Patching harmony...");
			}
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCTerminalMultiCodes";

		public const string PLUGIN_NAME = "LCTerminalMultiCodes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LCTerminalMultiCodes.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatch
	{
		[HarmonyPatch("OnShipLandedMiscEvents")]
		[HarmonyPostfix]
		private static void OnShipLandedMiscEventsPostfix(StartOfRound __instance)
		{
			if (!((Object)(object)__instance.currentLevel == (Object)null) && !(((Object)__instance.currentLevel).name == "CompanyBuildingLevel") && !(__instance.currentLevel.riskLevel == "Safe"))
			{
				TerminalPatch.Instance?.FindTerminalObjects();
			}
		}

		[HarmonyPatch("ShipHasLeft")]
		[HarmonyPostfix]
		private static void ShipHasLeftPostfix()
		{
			TerminalPatch.Instance?.ResetTerminalObjects();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch : MonoBehaviour
	{
		private ILookup<string, TerminalAccessibleObject> _wordToTerminalObjects = null;

		public static TerminalPatch Instance { get; private set; }

		public void ResetTerminalObjects()
		{
			ManualLogSource logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogDebug((object)string.Format("\"{0}\" Resetting {1} terminal objects", "TerminalPatch", _wordToTerminalObjects?.Count));
			}
			_wordToTerminalObjects = null;
		}

		public void FindTerminalObjects()
		{
			_wordToTerminalObjects = Object.FindObjectsOfType<TerminalAccessibleObject>().ToLookup((TerminalAccessibleObject x) => x.objectCode);
			ManualLogSource logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogDebug((object)string.Format("\"{0}\" Found {1} terminal objects", "TerminalPatch", _wordToTerminalObjects?.Count));
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(Terminal __instance)
		{
			Instance = ((Component)__instance).gameObject.AddComponent<TerminalPatch>();
		}

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPostfix]
		private static void ParsePlayerSentencePostfix(ref TerminalNode __result, Terminal __instance)
		{
			string text = __instance.screenText.text;
			int textAdded = __instance.textAdded;
			int length = text.Length;
			int num = length - textAdded;
			string text2 = text.Substring(num, length - num);
			text2 = __instance.RemovePunctuation(text2);
			string[] array = text2.Split(' ', StringSplitOptions.RemoveEmptyEntries);
			int num2 = (__instance.broadcastedCodeThisFrame ? 1 : 0);
			for (int i = num2; i < array.Length; i++)
			{
				__instance.CallFunctionInAccessibleTerminalObject(array[i]);
			}
			if (__instance.broadcastedCodeThisFrame && num2 == 0)
			{
				__instance.PlayBroadcastCodeEffect();
				if (__result == null)
				{
					__result = __instance.terminalNodes?.specialNodes?[19];
				}
			}
		}

		[HarmonyPatch("CallFunctionInAccessibleTerminalObject")]
		[HarmonyPrefix]
		private static bool CallFunctionInAccessibleTerminalObjectPrefix(Terminal __instance, string word)
		{
			IEnumerable<TerminalAccessibleObject> enumerable = Instance?._wordToTerminalObjects?[word];
			if (enumerable == null)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					logger.LogDebug((object)("\"TerminalPatch\" No valid objects for word \"" + word + "\", fallback to vanilla method"));
				}
				return true;
			}
			bool flag = false;
			foreach (TerminalAccessibleObject item in enumerable)
			{
				if ((Object)(object)item == (Object)null)
				{
					ManualLogSource logger2 = Plugin.Logger;
					if (logger2 != null)
					{
						logger2.LogDebug((object)("\"TerminalPatch\" Invalid object for word \"" + word + "\""));
					}
				}
				else
				{
					__instance.broadcastedCodeThisFrame = true;
					item.CallFunctionFromTerminal();
					flag = true;
				}
			}
			return !flag;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}