Decompiled source of CustomTerminal v1.1.0

CustomTerminal.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using CommandLib;
using CustomTerminal.Config;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[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 = "")]
[assembly: AssemblyCompany("CustomTerminal")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template mod for lethal company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomTerminal")]
[assembly: AssemblyTitle("CustomTerminal")]
[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 CustomTerminal
{
	public class ModInfo
	{
		public const string name = "Custom Terminal";

		public const string guid = "buzzbb.customterminal";

		public const string version = "1.0.0";
	}
	[BepInPlugin("buzzbb.customterminal", "Custom Terminal", "1.0.0")]
	public class Main : BaseUnityPlugin
	{
		private Harmony harmonyInstance = new Harmony("buzzbb.customterminal");

		private Color currentGamerRGB;

		public static Terminal terminalInstance;

		public static RawImage wallpaperInstance;

		private static Texture2D GetTextureFromFile(string path)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(1000, 1000);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			return val;
		}

		public static void RefreshAll()
		{
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)terminalInstance == (Object)null)
			{
				return;
			}
			Color val = default(Color);
			((Color)(ref val))..ctor(CustomTerminal.Config.Config.colorThemeR.Value / 255f, CustomTerminal.Config.Config.colorThemeG.Value / 255f, CustomTerminal.Config.Config.colorThemeB.Value / 255f);
			if (CustomTerminal.Config.Config.useWallpaper.Value)
			{
				if ((Object)(object)wallpaperInstance == (Object)null)
				{
					GameObject val2 = new GameObject("TerminalBackground");
					val2.transform.SetParent(((TMP_Text)terminalInstance.topRightText).transform.parent, false);
					val2.transform.localPosition = new Vector3(30f, 15f, 0f);
					val2.transform.localScale = new Vector3(5f, 5f, 5f);
					val2.transform.SetSiblingIndex(2);
					wallpaperInstance = val2.AddComponent<RawImage>();
					wallpaperInstance.texture = (Texture)(object)GetTextureFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "wallpaper.png"));
				}
				if (CustomTerminal.Config.Config.wallpaperColorTheme.Value)
				{
					((Graphic)wallpaperInstance).color = val;
				}
				else
				{
					((Graphic)wallpaperInstance).color = Color.white;
				}
			}
			terminalInstance.screenText.caretColor = val;
			((Graphic)terminalInstance.topRightText).color = val;
			((Graphic)terminalInstance.inputFieldText).color = val;
			((Graphic)((Selectable)terminalInstance.scrollBarVertical).image).color = val;
			((Graphic)((Component)terminalInstance.scrollBarVertical).GetComponent<Image>()).color = val;
			Image component = ((Component)((TMP_Text)terminalInstance.topRightText).transform.parent.GetChild(6)).GetComponent<Image>();
			((Graphic)component).color = new Color(val.r, val.g, val.b, ((Graphic)component).color.a);
			terminalInstance.terminalLight.color = val;
			terminalInstance.terminalLight.intensity = CustomTerminal.Config.Config.lightIntensity.Value;
		}

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Reached awake point for Custom [email protected], applying patches");
			harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Applied patches");
		}

		private void FixedUpdate()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)terminalInstance))
			{
				currentGamerRGB = Color.HSVToRGB(Mathf.PingPong(Time.time / 25f * CustomTerminal.Config.Config.rgbSpeed.Value, 1f), 1f, 1f);
				if (CustomTerminal.Config.Config.uiGamerMode.Value)
				{
					terminalInstance.screenText.caretColor = currentGamerRGB;
					((Graphic)terminalInstance.topRightText).color = currentGamerRGB;
					((Graphic)terminalInstance.inputFieldText).color = currentGamerRGB;
					((Graphic)((Selectable)terminalInstance.scrollBarVertical).image).color = currentGamerRGB;
					((Graphic)((Component)terminalInstance.scrollBarVertical).GetComponent<Image>()).color = currentGamerRGB;
					Image component = ((Component)((TMP_Text)terminalInstance.topRightText).transform.parent.GetChild(6)).GetComponent<Image>();
					((Graphic)component).color = new Color(currentGamerRGB.r, currentGamerRGB.g, currentGamerRGB.b, ((Graphic)component).color.a);
				}
				if (CustomTerminal.Config.Config.lightGamerMode.Value)
				{
					terminalInstance.terminalLight.color = currentGamerRGB;
				}
				if (CustomTerminal.Config.Config.wallpaperGamerMode.Value && CustomTerminal.Config.Config.useWallpaper.Value && (Object)(object)wallpaperInstance != (Object)null)
				{
					((Graphic)wallpaperInstance).color = currentGamerRGB;
				}
			}
		}
	}
}
namespace CustomTerminal.Patches
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class TerminalStartPatch
	{
		internal static void Postfix(Terminal __instance)
		{
			CustomTerminal.Config.Config.LoadConfig();
			Main.terminalInstance = __instance;
			Main.RefreshAll();
			Commands.RegisterCommand("refresh", "Refreshed configuration.\n", "ct_Refresh", __instance);
			Commands.RegisterCommand("uirgb", "Toggled the gamer RGB on UI elements.\n", "ct_ToggleUIRGB", __instance);
			Commands.RegisterCommand("lightrgb", "Toggled the gamer RGB on terminal lights.\n", "ct_ToggleLightRGB", __instance);
			Commands.RegisterCommand("wallpaperrgb", "Toggled the gamer RGB on your wallpaper.\n", "ct_ToggleWallpaperRGB", __instance);
			Commands.RegisterCommand("wallpapercolor", "Toggled the use of custom color theme for wallpaper.\n", "ct_ToggleWallpaperColor", __instance);
			Commands.RegisterCommand("wallpaper", "Toggled the use of wallpaper.\n", "ct_ToggleWallpaper", __instance);
			Commands.RegisterCommand("monitorstay", "Toggled monitor staying on when exiting the terminal.\n", "ct_ToggleUIStay", __instance);
			Commands.RegisterCommand("lightstay", "Toggled lights staying on when exiting the terminal.\n", "ct_ToggleLightStay", __instance);
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class TerminalDeactivePatch
	{
		internal static bool Prefix(Terminal __instance)
		{
			__instance.placeableObject.inUse = false;
			((Behaviour)__instance.terminalLight).enabled = CustomTerminal.Config.Config.lightStaysOn.Value;
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class TerminalInUseClientRPC
	{
		internal static void Postfix(Terminal __instance, bool inUse)
		{
			((MonoBehaviour)__instance).StopCoroutine("waitUntilFrameEndToSetActive");
			((Behaviour)__instance.terminalLight).enabled = CustomTerminal.Config.Config.lightStaysOn.Value || inUse;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class TerminalQuitPatch
	{
		internal static void Postfix(Terminal __instance)
		{
			if (CustomTerminal.Config.Config.monitorStaysOn.Value)
			{
				((MonoBehaviour)__instance).StartCoroutine(waitUntilFrameEndTwiceToSetActive(__instance));
			}
		}

		private static IEnumerator waitUntilFrameEndTwiceToSetActive(Terminal terminal)
		{
			yield return (object)new WaitForEndOfFrame();
			yield return (object)new WaitForEndOfFrame();
			((Component)terminal.terminalUIScreen).gameObject.SetActive(true);
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class TerminalRunEventPatch
	{
		internal static void Postfix(Terminal __instance, TerminalNode node)
		{
			if (string.IsNullOrWhiteSpace(node.terminalEvent))
			{
				return;
			}
			switch (node.terminalEvent)
			{
			case "ct_Refresh":
				CustomTerminal.Config.Config.LoadConfig();
				break;
			case "ct_ToggleUIRGB":
				CustomTerminal.Config.Config.uiGamerMode.Value = !CustomTerminal.Config.Config.uiGamerMode.Value;
				break;
			case "ct_ToggleLightRGB":
				CustomTerminal.Config.Config.lightGamerMode.Value = !CustomTerminal.Config.Config.lightGamerMode.Value;
				break;
			case "ct_ToggleWallpaper":
				if ((Object)(object)Main.wallpaperInstance == (Object)null)
				{
					CustomTerminal.Config.Config.useWallpaper.Value = true;
				}
				else if (CustomTerminal.Config.Config.useWallpaper.Value)
				{
					CustomTerminal.Config.Config.useWallpaper.Value = false;
					((Component)Main.wallpaperInstance).gameObject.SetActive(false);
				}
				else
				{
					CustomTerminal.Config.Config.useWallpaper.Value = true;
					((Component)Main.wallpaperInstance).gameObject.SetActive(true);
				}
				break;
			case "ct_ToggleWallpaperRGB":
				CustomTerminal.Config.Config.wallpaperGamerMode.Value = !CustomTerminal.Config.Config.wallpaperGamerMode.Value;
				break;
			case "ct_ToggleWallpaperColor":
				CustomTerminal.Config.Config.wallpaperColorTheme.Value = !CustomTerminal.Config.Config.wallpaperColorTheme.Value;
				break;
			case "ct_ToggleUIStay":
				CustomTerminal.Config.Config.monitorStaysOn.Value = !CustomTerminal.Config.Config.monitorStaysOn.Value;
				break;
			case "ct_ToggleLightStay":
				CustomTerminal.Config.Config.lightStaysOn.Value = !CustomTerminal.Config.Config.lightStaysOn.Value;
				break;
			}
			Main.RefreshAll();
		}
	}
}
namespace CustomTerminal.Config
{
	internal class Config
	{
		public static ConfigEntry<float> colorThemeR;

		public static ConfigEntry<float> colorThemeG;

		public static ConfigEntry<float> colorThemeB;

		public static ConfigEntry<float> uiAlpha;

		public static ConfigEntry<bool> uiGamerMode;

		public static ConfigEntry<float> lightIntensity;

		public static ConfigEntry<bool> lightStaysOn;

		public static ConfigEntry<bool> lightGamerMode;

		public static ConfigEntry<bool> useWallpaper;

		public static ConfigEntry<bool> wallpaperGamerMode;

		public static ConfigEntry<bool> wallpaperColorTheme;

		public static ConfigEntry<float> rgbSpeed;

		public static ConfigEntry<bool> monitorStaysOn;

		public static void LoadConfig()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "CustomTerminal.cfg"), true);
			colorThemeR = val.Bind<float>("Colors", "Red", 255f, "Red value between 0 and 255 for terminal color theme");
			colorThemeG = val.Bind<float>("Colors", "Green", 255f, "Green value between 0 and 255 for terminal color theme");
			colorThemeB = val.Bind<float>("Colors", "Blue", 255f, "Blue value between 0 and 255 for terminal color theme");
			uiAlpha = val.Bind<float>("UI", "Transparency", 255f, "Alpha value between 0 and 255 for all fully opaque terminal UI elements");
			uiGamerMode = val.Bind<bool>("UI", "Gamer RGB", true, "Whether or not to use gamer rgb for the ui element colors");
			lightIntensity = val.Bind<float>("Lights", "Intensity", 30f, "The intensity of the lights on the terminal that are by defualt only on when in the terminal");
			lightStaysOn = val.Bind<bool>("Lights", "Keep Lights On", true, "Whether or not to keep the lights on when outside of the terminal");
			lightGamerMode = val.Bind<bool>("Lights", "Gamer RGB", true, "Whether or not to use gamer rgb lights for the terminal light");
			useWallpaper = val.Bind<bool>("Wallpaper", "Enabled", true, "Enables the use of a loaded wallpaper from the mod directory with the name 'wallpaper.png'");
			wallpaperGamerMode = val.Bind<bool>("Wallpaper", "Gamer RGB", true, "Whether or not to use gamer rgb for the wallpaper color, recommended to keep on true if light is on gamer mode to look like it is effected by light");
			wallpaperColorTheme = val.Bind<bool>("Wallpaper", "Use Color Theme", false, "Whether or not to use custom color theme color for wallpaper color, if this and gamer rgb are turned off, wallpaper will be normal color");
			rgbSpeed = val.Bind<float>("Misc", "RGB Speed", 1f, "The speed at which the RGB mode fades through colors");
			monitorStaysOn = val.Bind<bool>("Misc", "Keep Monitor On", true, "Keeps the monitor on even when the terminal is not in use");
		}
	}
}