Decompiled source of ReduceUI v2.1.1

ReduceUI.dll

Decompiled 7 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Receiver2;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ReduceUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReduceUI")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("23e25a6a-a13c-4357-825d-49d46a394f4b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ReduceUI;

[BepInProcess("Receiver2.exe")]
[BepInPlugin("SmilingLizard.plugins.ReduceUI", "ReduceUI", "2.1.1")]
public class ReduceUI : BaseUnityPlugin
{
	private enum Elem
	{
		InventoryFrame,
		InventoryNumbers,
		InventoryEmpty,
		Rank,
		Holster,
		TapeFrame,
		TapeIcon,
		TapeCounter,
		TapeQueue,
		SubtitleFrame,
		SubtitleWaveform,
		GunHelp,
		PopupMessages,
		PopupHelp,
		InteractKey,
		Count
	}

	private static ReduceUI instance;

	private GameObject tutorial;

	private Dictionary<Elem, List<Behaviour>> elems;

	private Dictionary<Elem, ConfigEntry<bool>> show;

	private ConfigEntry<KeyboardShortcut> tapeKey;

	public void Awake()
	{
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		if (instance == null)
		{
			instance = this;
			show = new Dictionary<Elem, ConfigEntry<bool>>
			{
				[Elem.InventoryFrame] = ((BaseUnityPlugin)this).Config.Bind<bool>("Inventory", "Frame", true, "Toggles visibility of the frame around inventory items in the bottom left."),
				[Elem.InventoryNumbers] = ((BaseUnityPlugin)this).Config.Bind<bool>("Inventory", "Numbers", true, "Toggles visibility of the numbers in the inventory slots."),
				[Elem.InventoryEmpty] = ((BaseUnityPlugin)this).Config.Bind<bool>("Inventory", "Empty Slots", true, "Toggles visibility of the \"Empty\" indicator in empty inventory slots."),
				[Elem.Rank] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Rank Indicator", true, "Toggles visibility of the rank indicator icon."),
				[Elem.Holster] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Holster Frame", true, "Toggles visibility of the frame around the holster slot."),
				[Elem.TapeFrame] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Tape Frame", true, "Toggles visibility of the frame around the tape UI group."),
				[Elem.TapeIcon] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Tape Icon", true, "Toggles visibility of the tape icon in the tape UI group."),
				[Elem.TapeCounter] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Tape Counter", true, "Toggles visibility of the tape counter."),
				[Elem.TapeQueue] = ((BaseUnityPlugin)this).Config.Bind<bool>("Bottom Right Group", "Tape Queue", true, "Toggles visibility of the number of queued tapes."),
				[Elem.SubtitleFrame] = ((BaseUnityPlugin)this).Config.Bind<bool>("Subtitles", "Frame", true, "Toggles visibility of the frame around subtitles."),
				[Elem.SubtitleWaveform] = ((BaseUnityPlugin)this).Config.Bind<bool>("Subtitles", "Waveform Icon", true, "Toggles the visibility of the Waveform icon when playing tapes."),
				[Elem.GunHelp] = ((BaseUnityPlugin)this).Config.Bind<bool>("Tutorials", "Gun Help", true, "Toggles visibility of the gun help menu in the top right."),
				[Elem.PopupMessages] = ((BaseUnityPlugin)this).Config.Bind<bool>("Tutorials", "Messages", true, "Toggles visibility of pop-up messages, like \"Collect 5 tapes\" or \"The voice of the Threat is taking control\"."),
				[Elem.PopupHelp] = ((BaseUnityPlugin)this).Config.Bind<bool>("Tutorials", "In World Help", true, "Toggles visibility of in-world help messages, like 'Holster your gun to hack'."),
				[Elem.InteractKey] = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Interact Key", true, "Toggles visibility of the \"G\" in interaction and hacking prompts. May not apply immediately.")
			};
			tapeKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("KeyBinding", "Show Tape Counter", KeyboardShortcut.Empty, "If the tape counter and/or queue are hidden, hold this key to temporarily show them.");
			((BaseUnityPlugin)this).Config.SettingChanged += OnSettingsChanged;
			Harmony.CreateAndPatchAll(typeof(ReduceUI), (string)null);
		}
	}

	private void OnSettingsChanged(object sender, SettingChangedEventArgs args)
	{
		if (Init())
		{
			Apply();
		}
	}

	private bool OtherKeys()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = tapeKey.Value;
		foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers)
		{
			if (!Input.GetKey(modifier))
			{
				return false;
			}
		}
		return true;
	}

	public void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = tapeKey.Value;
		if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey) && OtherKeys())
		{
			Behaviour val = elems[Elem.TapeCounter][0];
			if (val != null)
			{
				val.enabled = true;
			}
			Behaviour val2 = elems[Elem.TapeQueue][0];
			if (val2 != null)
			{
				val2.enabled = true;
			}
			return;
		}
		value = tapeKey.Value;
		if (!Input.GetKeyUp(((KeyboardShortcut)(ref value)).MainKey))
		{
			return;
		}
		if (!show[Elem.TapeCounter].Value)
		{
			Behaviour val3 = elems[Elem.TapeCounter][0];
			if (val3 != null)
			{
				val3.enabled = false;
			}
		}
		if (!show[Elem.TapeQueue].Value)
		{
			Behaviour val4 = elems[Elem.TapeQueue][0];
			if (val4 != null)
			{
				val4.enabled = false;
			}
		}
	}

	private void Apply()
	{
		for (int i = 0; i < 15; i++)
		{
			foreach (Behaviour item in elems[(Elem)i])
			{
				item.enabled = show[(Elem)i].Value;
			}
		}
		tutorial.SetActive(show[Elem.GunHelp].Value);
	}

	private bool Init()
	{
		GameObject val = GameObject.Find("/ReceiverCore/PlayerGUI/Canvas/gameplay");
		if (val == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Tried to init but couldn't find gui; aborting");
			return false;
		}
		Transform transform = val.transform;
		LocalAimHandler val2 = default(LocalAimHandler);
		if (!LocalAimHandler.TryGetInstance(ref val2))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"Tried to init but couldn't find player; aborting");
			return false;
		}
		if (elems == null)
		{
			elems = new Dictionary<Elem, List<Behaviour>>(15);
		}
		if (!elems.ContainsKey(Elem.InventoryFrame))
		{
			elems[Elem.InventoryFrame] = new List<Behaviour>(8);
		}
		else
		{
			elems[Elem.InventoryFrame].Clear();
		}
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 1")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 2")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 3")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 4")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 5")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/GUI Line Text/Layout Group/Text")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/GUI Line Text/Layout Group/Line Bottom Line Right")).GetComponent<Image>());
		elems[Elem.InventoryFrame].Add((Behaviour)(object)((Component)transform.Find("Inventory/GUI Line Text/Line Bottom Right Cross")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.InventoryNumbers))
		{
			elems[Elem.InventoryNumbers] = new List<Behaviour>(5);
		}
		else
		{
			elems[Elem.InventoryNumbers].Clear();
		}
		TextMeshProUGUI component = ((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 1/Number")).GetComponent<TextMeshProUGUI>();
		elems[Elem.InventoryNumbers].Add((Behaviour)(object)component);
		elems[Elem.InventoryNumbers].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 2/Number")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryNumbers].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 3/Number")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryNumbers].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 4/Number")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryNumbers].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 5/Number")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.InventoryEmpty))
		{
			elems[Elem.InventoryEmpty] = new List<Behaviour>(5);
		}
		else
		{
			elems[Elem.InventoryEmpty].Clear();
		}
		elems[Elem.InventoryEmpty].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 1/Empty")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryEmpty].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 2/Empty")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryEmpty].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 3/Empty")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryEmpty].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 4/Empty")).GetComponent<TextMeshProUGUI>());
		elems[Elem.InventoryEmpty].Add((Behaviour)(object)((Component)transform.Find("Inventory/Inventory Slots/GUI Inventory Slot 5/Empty")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.Rank))
		{
			elems[Elem.Rank] = new List<Behaviour>(5);
		}
		else
		{
			elems[Elem.Rank].Clear();
		}
		elems[Elem.Rank].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Rank/Beginner")).GetComponent<Image>());
		elems[Elem.Rank].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Rank/Sleeper")).GetComponent<Image>());
		elems[Elem.Rank].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Rank/Sleepwalker")).GetComponent<Image>());
		elems[Elem.Rank].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Rank/Liminal")).GetComponent<Image>());
		elems[Elem.Rank].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Rank/Awake")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.Holster))
		{
			elems[Elem.Holster] = new List<Behaviour>(8);
		}
		else
		{
			elems[Elem.Holster].Clear();
		}
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line Text/Line Bottom Left Vertical")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line Text/Layout Group/Line Bottom Line left")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line Text/Layout Group/Text")).GetComponent<TextMeshProUGUI>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line Text/Layout Group/Line Bottom Line Right")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line Text/Line Bottom Right Cross")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line/Line Bottom Left Cross")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line/Line Bottom")).GetComponent<Image>());
		elems[Elem.Holster].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Left layout Group/GUI Line/Line Bottom Right Cross")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.TapeFrame))
		{
			elems[Elem.TapeFrame] = new List<Behaviour>(9);
		}
		else
		{
			elems[Elem.TapeFrame].Clear();
		}
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line Text/Line Bottom Left Vertical")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line Text/Layout Group/Line Bottom Line left")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line Text/Layout Group/Text")).GetComponent<TextMeshProUGUI>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line Text/Layout Group/Line Bottom Line Right")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line Text/Line Bottom Right Cross")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line (1)/Line Bottom")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line/Line Bottom Left Cross")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line/Line Bottom")).GetComponent<Image>());
		elems[Elem.TapeFrame].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Line/Line Bottom Right Cross")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.TapeIcon))
		{
			elems[Elem.TapeIcon] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.TapeIcon].Clear();
		}
		elems[Elem.TapeIcon].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Tapes/Tape Counter/Tape")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.TapeCounter))
		{
			elems[Elem.TapeCounter] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.TapeCounter].Clear();
		}
		elems[Elem.TapeCounter].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/GUI Tapes/Tape Counter/Global Counter")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.TapeQueue))
		{
			elems[Elem.TapeQueue] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.TapeQueue].Clear();
		}
		elems[Elem.TapeQueue].Add((Behaviour)(object)((Component)transform.Find("Bottom Right Layout Group/Bottom Bottom Right Layout Group/Bottom Bottom Right Right Layout Group/Queued Tape Counter")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.SubtitleFrame))
		{
			elems[Elem.SubtitleFrame] = new List<Behaviour>(8);
		}
		else
		{
			elems[Elem.SubtitleFrame].Clear();
		}
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Top line/Line Bottom Left Vertical")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Top line/Layout Group/Line Bottom Line left")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Top line/Layout Group/Text")).GetComponent<TextMeshProUGUI>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Top line/Layout Group/Line Bottom Line Right")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Top line/Line Bottom Right Cross")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Bottom Line/Line Bottom Left Cross")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Bottom Line/Line Bottom")).GetComponent<Image>());
		elems[Elem.SubtitleFrame].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Bottom Line/Line Bottom Right Cross")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.SubtitleWaveform))
		{
			elems[Elem.SubtitleWaveform] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.SubtitleWaveform].Clear();
		}
		elems[Elem.SubtitleWaveform].Add((Behaviour)(object)((Component)transform.Find("subtitle_region/Waveform Visualization Container")).GetComponent<Image>());
		if (!elems.ContainsKey(Elem.PopupMessages))
		{
			elems[Elem.PopupMessages] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.PopupMessages].Clear();
		}
		elems[Elem.PopupMessages].Add((Behaviour)(object)((Component)transform.Find("Event Message Text")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.PopupHelp))
		{
			elems[Elem.PopupHelp] = new List<Behaviour>(1);
		}
		else
		{
			elems[Elem.PopupHelp].Clear();
		}
		elems[Elem.PopupHelp].Add((Behaviour)(object)((Component)transform.Find("in_world_tutorial_text")).GetComponent<TextMeshProUGUI>());
		if (!elems.ContainsKey(Elem.GunHelp))
		{
			elems[Elem.GunHelp] = new List<Behaviour>(0);
		}
		tutorial = ((Component)transform.Find("tutorial_text_container")).gameObject;
		if (!elems.ContainsKey(Elem.InteractKey))
		{
			elems[Elem.InteractKey] = new List<Behaviour>(2);
		}
		else
		{
			elems[Elem.InteractKey].Clear();
		}
		elems[Elem.InteractKey].Add((Behaviour)(object)val2.get_help_text);
		elems[Elem.InteractKey].Add((Behaviour)(object)val2.hacking_minigame.text);
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ReceiverCoreScript), "SpawnPlayer")]
	public static void Attach()
	{
		if (instance.Init())
		{
			instance.Apply();
		}
	}
}