Decompiled source of LateGameUpgrades Gui v0.1.0

LGUGui.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using MoreShipUpgrades.API;
using MoreShipUpgrades.Managers;
using MoreShipUpgrades.UI.TerminalNodes;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LGUGui")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Dice Addon")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8c26ccb3fcac04ac5ec671a536631dfe51490ba1")]
[assembly: AssemblyProduct("LGUGui")]
[assembly: AssemblyTitle("LGUGui")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 LGUGui
{
	public class ConfigManager
	{
		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void setupLethalConfig()
		{
			//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_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			ConfigEntry<float> transparency = Plugin.transparency;
			FloatSliderOptions val = new FloatSliderOptions();
			((BaseRangeOptions<float>)val).Min = 0f;
			((BaseRangeOptions<float>)val).Max = 1f;
			((BaseOptions)val).RequiresRestart = false;
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(transparency, val);
			ConfigEntry<float> openSpeed = Plugin.openSpeed;
			FloatSliderOptions val3 = new FloatSliderOptions();
			((BaseRangeOptions<float>)val3).Min = 0f;
			((BaseRangeOptions<float>)val3).Max = 1f;
			((BaseOptions)val3).RequiresRestart = false;
			FloatSliderConfigItem val4 = new FloatSliderConfigItem(openSpeed, val3);
			TextDropDownConfigItem val5 = new TextDropDownConfigItem(Plugin.selectedFontName, false);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
		}
	}
	public class IngameKeybinds : LcInputActions
	{
		[InputAction("<Keyboard>/p", Name = "PurchaseMenu")]
		public InputAction PurchaseMenu { get; set; } = null;

	}
	public class MoreShipUpgradesPatch
	{
		[HarmonyPatch(typeof(LguStore), "HandleUpgradeClientRpc")]
		private class Patch_LGU_HandleUpgrade
		{
			private static void Postfix(string name, bool increment)
			{
				new PurchaseMenu().refresh();
			}
		}

		[HarmonyPatch(typeof(CurrencyManager), "TradePlayerCreditsClientRpc")]
		private class Patch_LGU_HandleTrade
		{
			private static void Postfix(ulong traderClientId, int playerCreditAmount, ClientRpcParams clientRpcParams)
			{
				new PurchaseMenu().refresh(trade: true);
			}
		}

		[HarmonyPatch(typeof(CurrencyManager), "AddCurrencyAmountFromQuotaClientRpc")]
		private class Patch_LGU_AddCurrencyAmountFromQuota
		{
			private static void Postfix(int quotaFullfilled)
			{
				if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsOwner)
				{
					PurchaseMenu.totalPoints += Mathf.RoundToInt((float)(CurrencyManager.Instance.GetCurrencyAmountFromQuota(quotaFullfilled) / 2));
				}
			}
		}
	}
	[BepInPlugin("Slayer6409.LGU_GUI", "LGU_GUI", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Slayer6409.LGU_GUI";

		private const string modName = "LGU_GUI";

		private const string modVersion = "0.1.0";

		public static AssetBundle LoadedAssets;

		public static ManualLogSource CustomLogger;

		public static GameObject NetworkerPrefab;

		public static GameObject PurchaseMenuPrefab;

		public static GameObject UpgradeButton;

		public static GameObject TradePrefab;

		internal static IngameKeybinds Keybinds = null;

		public static ConfigFile ClientSideConfigs = null;

		private static readonly string directoryPath = Path.Combine(Application.persistentDataPath, "LGU_GUI");

		private readonly Harmony harmony = new Harmony("Slayer6409.LGU_GUI");

		public static ConfigEntry<bool> onlyInOrbit;

		public static ConfigEntry<bool> onlyOnShip;

		public static ConfigEntry<bool> extendedLog;

		public static ConfigEntry<bool> adminStuff;

		public static ConfigEntry<float> transparency;

		public static ConfigEntry<float> openSpeed;

		public static ConfigEntry<string> selectedFontName;

		public static Dictionary<string, TMP_FontAsset> fonts = new Dictionary<string, TMP_FontAsset>();

		private void Awake()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			CustomLogger = Logger.CreateLogSource("LateGameUpgrades GUI");
			if (!Directory.Exists(directoryPath))
			{
				Directory.CreateDirectory(directoryPath);
			}
			LoadedAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lgugui"));
			ClientSideConfigs = new ConfigFile(Path.Combine(directoryPath, "LGU_GUI_ClientSide.json"), true);
			PurchaseMenuPrefab = LoadedAssets.LoadAsset<GameObject>("PurchaseGUI");
			PurchaseMenuPrefab.AddComponent<MenuController>();
			PurchaseMenuPrefab.AddComponent<UIFadeEffect>();
			UpgradeButton = LoadedAssets.LoadAsset<GameObject>("UpgradePrefab");
			TradePrefab = LoadedAssets.LoadAsset<GameObject>("TradePrefab");
			fonts.Add("ARIAL", LoadedAssets.LoadAsset<TMP_FontAsset>("ARIAL SDF"));
			fonts.Add("LiberationSans", LoadedAssets.LoadAsset<TMP_FontAsset>("LiberationSans SDF"));
			fonts.Add("3270-Regular", LoadedAssets.LoadAsset<TMP_FontAsset>("3270-Regular SDF"));
			fonts.Add("Comic Sans", LoadedAssets.LoadAsset<TMP_FontAsset>("Comic Sans MS SDF"));
			fonts.Add("Party Vibes", LoadedAssets.LoadAsset<TMP_FontAsset>("Party Vibes SDF"));
			fonts.Add("Perfect DOS VGA 437", LoadedAssets.LoadAsset<TMP_FontAsset>("Perfect DOS VGA 437 SDF"));
			fonts.Add("shlop rg", LoadedAssets.LoadAsset<TMP_FontAsset>("shlop rg SDF"));
			fonts.Add("WEBDINGS", LoadedAssets.LoadAsset<TMP_FontAsset>("WEBDINGS SDF"));
			fonts.Add("Lizzie", LoadedAssets.LoadAsset<TMP_FontAsset>("Lizzie-vmnD SDF"));
			fonts.Add("Seven Segment", LoadedAssets.LoadAsset<TMP_FontAsset>("Seven Segment SDF"));
			fonts.Add("Conthrax-SemiBold", LoadedAssets.LoadAsset<TMP_FontAsset>("Conthrax-SemiBold SDF"));
			fonts.Add("Astronomus", LoadedAssets.LoadAsset<TMP_FontAsset>("Astronomus SDF"));
			fonts.Add("ciacode39_m", LoadedAssets.LoadAsset<TMP_FontAsset>("ciacode39_m SDF"));
			fonts.Add("DOTMATRI", LoadedAssets.LoadAsset<TMP_FontAsset>("DOTMATRI SDF"));
			fonts.Add("Minecrafter.Reg", LoadedAssets.LoadAsset<TMP_FontAsset>("Minecrafter.Reg SDF"));
			configSetup();
			harmony.PatchAll();
			Keybinds = new IngameKeybinds();
			Keybinds.PurchaseMenu.performed += delegate
			{
				tryShowMenu();
			};
			selectedFontName.SettingChanged += delegate
			{
				changeFont();
			};
			if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"))
			{
				ConfigManager.setupLethalConfig();
			}
			CustomLogger.LogInfo((object)"Plugin LGUGui is loaded!");
		}

		public static void ExtendedLogging(string msg, LogLevel level = 16)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (extendedLog.Value)
			{
				CustomLogger.Log(level, (object)msg);
			}
		}

		public void configSetup()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			onlyInOrbit = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "Only In Orbit", false, "Makes it to where you are only able to upgrade in orbit.");
			onlyOnShip = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "Only On Ship", true, "Makes it to where you are only able to upgrade pn the ship.");
			extendedLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "Extended Logging", false, "Log more debug stuff");
			adminStuff = ((BaseUnityPlugin)this).Config.Bind<bool>("Main", "Admin Mode", false, "Enable the Admin Button");
			string[] array = fonts.Keys.ToArray();
			selectedFontName = ClientSideConfigs.Bind<string>("Client Side", "Selected Font", array.Contains("LiberationSans") ? "LiberationSans" : array.First(), new ConfigDescription("Select which font to use in the LGU GUI.", (AcceptableValueBase)(object)new AcceptableValueList<string>(array), Array.Empty<object>()));
			transparency = ClientSideConfigs.Bind<float>("Client Side", "Transparency", 0.93f, "Sets the transparency of the GUI.");
			openSpeed = ClientSideConfigs.Bind<float>("Client Side", "Open Speed", 0.15f, "Sets the open animation speed of the GUI.");
		}

		public static void changeFont()
		{
			if ((Object)(object)PurchaseMenu.menu != (Object)null)
			{
				ApplyFontTo(PurchaseMenu.menu);
			}
		}

		public static void ApplyFontTo(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			if (fonts.TryGetValue(selectedFontName.Value, out var value))
			{
				TextMeshProUGUI[] componentsInChildren = root.GetComponentsInChildren<TextMeshProUGUI>(true);
				foreach (TextMeshProUGUI val in componentsInChildren)
				{
					((TMP_Text)val).font = value;
				}
				CustomLogger.LogInfo((object)("Applied font '" + selectedFontName.Value + "' to purchase menu."));
			}
			else
			{
				CustomLogger.LogWarning((object)("Font '" + selectedFontName.Value + "' not found when trying to apply to purchase menu."));
			}
		}

		public void tryShowMenu()
		{
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if (!((Object)(object)val == (Object)null) && (!val.quickMenuManager.isMenuOpen || PurchaseMenu.menu.activeInHierarchy) && (!onlyInOrbit.Value || StartOfRound.Instance.inShipPhase) && (!onlyOnShip.Value || val.isInHangarShipRoom) && !val.inTerminalMenu && !val.isTypingChat)
			{
				if ((Object)(object)PurchaseMenu.menu != (Object)null && PurchaseMenu.menu.activeInHierarchy)
				{
					PurchaseMenu.menuController.CloseMenu();
				}
				else
				{
					PurchaseMenu.initMenu();
				}
			}
		}
	}
	public class PurchaseMenu
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__showTradeGui;

			public static UnityAction <1>__showAdminGui;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction<float> <>9__17_1;

			public static UnityAction<float> <>9__17_2;

			public static UnityAction <>9__17_3;

			public static UnityAction <>9__17_4;

			public static UnityAction <>9__17_5;

			public static UnityAction <>9__17_6;

			public static UnityAction <>9__17_7;

			public static UnityAction <>9__17_8;

			public static Func<CustomTerminalNode, string> <>9__22_1;

			public static Func<PlayerControllerB, string> <>9__26_0;

			public static Func<PlayerControllerB, string> <>9__27_0;

			internal void <initMenu>b__17_1(float value)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				Plugin.transparency.Value = value;
				foreach (Graphic graphic in fader.graphics)
				{
					if ((Object)(object)graphic != (Object)null)
					{
						Color color = graphic.color;
						color.a = value;
						graphic.color = color;
					}
				}
			}

			internal void <initMenu>b__17_2(float value)
			{
				Plugin.openSpeed.Value = value;
			}

			internal void <initMenu>b__17_3()
			{
				showUpgrades(shared: true);
			}

			internal void <initMenu>b__17_4()
			{
				showUpgrades(shared: false);
			}

			internal void <initMenu>b__17_5()
			{
				showSettingsMenu(settings: true);
			}

			internal void <initMenu>b__17_6()
			{
				showSettingsMenu(settings: false);
			}

			internal void <initMenu>b__17_7()
			{
				menuController.CloseMenu();
			}

			internal void <initMenu>b__17_8()
			{
				menuController.CloseMenu();
			}

			internal string <showUpgrades>b__22_1(CustomTerminalNode x)
			{
				return x.Name;
			}

			internal string <showAdminGui>b__26_0(PlayerControllerB p)
			{
				return p.playerUsername;
			}

			internal string <showTradeGui>b__27_0(PlayerControllerB p)
			{
				return p.playerUsername;
			}
		}

		public static GameObject menu;

		public static MenuController menuController;

		public static GameObject mainScreen;

		public static GameObject settingsScreen;

		public static TMP_Text currencyText;

		public static UIFadeEffect fader;

		public static bool isTrackedYet = false;

		public static Transform mainScrollContent;

		public static Transform ListUpgrades;

		public static Transform PurchaseUpgrade;

		public static Color NormalTextColor = new Color(0.02942256f, 0.8113208f, 0f, 1f);

		public static Color RedTextColor = new Color(0.7169812f, 0.03853131f, 0f, 1f);

		public static Color SaleColor = new Color(0f, 0.7f, 1f, 1f);

		public static int totalPoints = 0;

		public static CustomTerminalNode currentSelection;

		public static string location;

		private static bool isOpening = false;

		public static void initMenu()
		{
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Expected O, but got Unknown
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Expected O, but got Unknown
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Expected O, but got Unknown
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Expected O, but got Unknown
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Expected O, but got Unknown
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Expected O, but got Unknown
			//IL_04be: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Expected O, but got Unknown
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Expected O, but got Unknown
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0557: Expected O, but got Unknown
			if (isOpening || ((Object)(object)menu != (Object)null && menu.activeInHierarchy))
			{
				return;
			}
			isOpening = true;
			try
			{
				Plugin.ExtendedLogging("Initializing LGU Menu", (LogLevel)16);
				if ((Object)(object)StartOfRound.Instance?.localPlayerController?.quickMenuManager == (Object)null || (Object)(object)CurrencyManager.Instance == (Object)null)
				{
					Plugin.ExtendedLogging("Aborting menu init: StartOfRound or CurrencyManager is null", (LogLevel)16);
					return;
				}
				if ((Object)(object)menu == (Object)null)
				{
					menu = Object.Instantiate<GameObject>(Plugin.PurchaseMenuPrefab);
					if ((Object)(object)menuController == (Object)null)
					{
						menu.AddComponent<MenuController>();
					}
					menuController = menu.GetComponent<MenuController>();
					mainScreen = ((Component)menu.transform.Find("Background")).gameObject;
					settingsScreen = ((Component)menu.transform.Find("SettingsMenu")).gameObject;
					currencyText = ((Component)mainScreen.transform.Find("TotalPoints")).GetComponent<TMP_Text>();
					fader = menu.GetComponent<UIFadeEffect>();
					if ((Object)(object)fader == (Object)null)
					{
						fader = menu.AddComponent<UIFadeEffect>();
					}
					Button component = ((Component)mainScreen.transform.Find("SharedUpgrades")).GetComponent<Button>();
					Button component2 = ((Component)mainScreen.transform.Find("IndividualUpgrades")).GetComponent<Button>();
					Button component3 = ((Component)mainScreen.transform.Find("TradePoints")).GetComponent<Button>();
					Button component4 = ((Component)mainScreen.transform.Find("Reset")).GetComponent<Button>();
					Button component5 = ((Component)mainScreen.transform.Find("Settings")).GetComponent<Button>();
					Button component6 = ((Component)settingsScreen.transform.Find("Back")).GetComponent<Button>();
					mainScrollContent = mainScreen.transform.Find("ListUpgrades/Scroll View/Viewport/Content");
					ListUpgrades = mainScreen.transform.Find("ListUpgrades");
					PurchaseUpgrade = mainScreen.transform.Find("PurchaseUpgrade");
					List<OptionData> list = new List<OptionData>();
					list.Add(new OptionData(Plugin.selectedFontName.Value));
					foreach (KeyValuePair<string, TMP_FontAsset> font in Plugin.fonts)
					{
						if (!(font.Key == Plugin.selectedFontName.Value))
						{
							list.Add(new OptionData(font.Key));
						}
					}
					Slider component7 = ((Component)settingsScreen.transform.Find("TransparencySlider")).GetComponent<Slider>();
					Slider component8 = ((Component)settingsScreen.transform.Find("TimeSlider")).GetComponent<Slider>();
					TMP_Dropdown fontDropdown = ((Component)settingsScreen.transform.Find("Dropdown")).GetComponent<TMP_Dropdown>();
					fontDropdown.ClearOptions();
					fontDropdown.options = list;
					fontDropdown.value = 0;
					((UnityEvent<int>)(object)fontDropdown.onValueChanged).AddListener((UnityAction<int>)delegate(int index)
					{
						Plugin.selectedFontName.Value = fontDropdown.options[index].text;
					});
					component7.value = Plugin.transparency.Value;
					((UnityEvent<float>)(object)component7.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
					{
						//IL_0036: Unknown result type (might be due to invalid IL or missing references)
						//IL_003b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0045: Unknown result type (might be due to invalid IL or missing references)
						Plugin.transparency.Value = value;
						foreach (Graphic graphic in fader.graphics)
						{
							if ((Object)(object)graphic != (Object)null)
							{
								Color color = graphic.color;
								color.a = value;
								graphic.color = color;
							}
						}
					});
					component8.value = Plugin.openSpeed.Value;
					((UnityEvent<float>)(object)component8.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
					{
						Plugin.openSpeed.Value = value;
					});
					ButtonClickedEvent onClick = component.onClick;
					object obj = <>c.<>9__17_3;
					if (obj == null)
					{
						UnityAction val = delegate
						{
							showUpgrades(shared: true);
						};
						<>c.<>9__17_3 = val;
						obj = (object)val;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					ButtonClickedEvent onClick2 = component2.onClick;
					object obj2 = <>c.<>9__17_4;
					if (obj2 == null)
					{
						UnityAction val2 = delegate
						{
							showUpgrades(shared: false);
						};
						<>c.<>9__17_4 = val2;
						obj2 = (object)val2;
					}
					((UnityEvent)onClick2).AddListener((UnityAction)obj2);
					ButtonClickedEvent onClick3 = component5.onClick;
					object obj3 = <>c.<>9__17_5;
					if (obj3 == null)
					{
						UnityAction val3 = delegate
						{
							showSettingsMenu(settings: true);
						};
						<>c.<>9__17_5 = val3;
						obj3 = (object)val3;
					}
					((UnityEvent)onClick3).AddListener((UnityAction)obj3);
					ButtonClickedEvent onClick4 = component6.onClick;
					object obj4 = <>c.<>9__17_6;
					if (obj4 == null)
					{
						UnityAction val4 = delegate
						{
							showSettingsMenu(settings: false);
						};
						<>c.<>9__17_6 = val4;
						obj4 = (object)val4;
					}
					((UnityEvent)onClick4).AddListener((UnityAction)obj4);
					ButtonClickedEvent onClick5 = component3.onClick;
					object obj5 = <>O.<0>__showTradeGui;
					if (obj5 == null)
					{
						UnityAction val5 = showTradeGui;
						<>O.<0>__showTradeGui = val5;
						obj5 = (object)val5;
					}
					((UnityEvent)onClick5).AddListener((UnityAction)obj5);
					Button component9 = ((Component)mainScreen.transform.Find("xButton")).GetComponent<Button>();
					ButtonClickedEvent onClick6 = component9.onClick;
					object obj6 = <>c.<>9__17_7;
					if (obj6 == null)
					{
						UnityAction val6 = delegate
						{
							menuController.CloseMenu();
						};
						<>c.<>9__17_7 = val6;
						obj6 = (object)val6;
					}
					((UnityEvent)onClick6).AddListener((UnityAction)obj6);
					Button component10 = ((Component)settingsScreen.transform.Find("xButton")).GetComponent<Button>();
					ButtonClickedEvent onClick7 = component10.onClick;
					object obj7 = <>c.<>9__17_8;
					if (obj7 == null)
					{
						UnityAction val7 = delegate
						{
							menuController.CloseMenu();
						};
						<>c.<>9__17_8 = val7;
						obj7 = (object)val7;
					}
					((UnityEvent)onClick7).AddListener((UnityAction)obj7);
				}
				Button component11 = ((Component)mainScreen.transform.Find("Admin")).GetComponent<Button>();
				TMP_Text component12 = ((Component)mainScreen.transform.Find("AllPoints")).GetComponent<TMP_Text>();
				if (Plugin.adminStuff.Value && (((NetworkBehaviour)StartOfRound.Instance).IsHost || StartOfRound.Instance.localPlayerController.playerSteamId == 76561198077184650L))
				{
					Plugin.ExtendedLogging("Admin Stuff", (LogLevel)16);
					((Component)component12).gameObject.SetActive(true);
					component12.text = totalPoints.ToString();
					((Component)component11).gameObject.SetActive(true);
					ButtonClickedEvent onClick8 = component11.onClick;
					object obj8 = <>O.<1>__showAdminGui;
					if (obj8 == null)
					{
						UnityAction val8 = showAdminGui;
						<>O.<1>__showAdminGui = val8;
						obj8 = (object)val8;
					}
					((UnityEvent)onClick8).AddListener((UnityAction)obj8);
				}
				Plugin.ApplyFontTo(menu);
				currencyText.text = CurrencyManager.Instance.CurrencyAmount.ToString();
				resetView();
				menu.SetActive(true);
				fader.FadeIn();
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				menuController.Reopen();
				StartOfRound.Instance.localPlayerController.quickMenuManager.isMenuOpen = true;
			}
			finally
			{
				isOpening = false;
			}
		}

		public static void resetView()
		{
			mainScreen.gameObject.SetActive(true);
			((Component)PurchaseUpgrade).gameObject.SetActive(false);
			((Component)ListUpgrades).gameObject.SetActive(false);
			settingsScreen.gameObject.SetActive(false);
		}

		public static void LogTransformTree(Transform t, string prefix = "")
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			Plugin.ExtendedLogging(prefix + ((Object)t).name, (LogLevel)16);
			foreach (Transform item in t)
			{
				Transform t2 = item;
				LogTransformTree(t2, prefix + ((Object)t).name + "/");
			}
		}

		public static void clearMainViewport()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			foreach (Transform item in mainScrollContent)
			{
				Transform val = item;
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}

		public static void swapTwo(bool purchase)
		{
			((Component)PurchaseUpgrade).gameObject.SetActive(purchase);
			((Component)ListUpgrades).gameObject.SetActive(!purchase);
		}

		public static void showUpgrades(bool shared)
		{
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Expected O, but got Unknown
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			currentSelection = null;
			location = "showUpgrades," + shared;
			swapTwo(purchase: false);
			int currencyAmount = CurrencyManager.Instance.CurrencyAmount;
			currencyText.text = currencyAmount.ToString();
			clearMainViewport();
			List<CustomTerminalNode> upgradeNodes = UpgradeApi.GetUpgradeNodes();
			IOrderedEnumerable<CustomTerminalNode> orderedEnumerable = from x in upgradeNodes
				where x.SharedUpgrade == shared
				orderby x.Name
				select x;
			foreach (CustomTerminalNode upgrade in orderedEnumerable)
			{
				int currentPrice = upgrade.GetCurrentPrice();
				int num = (upgrade.AlternateCurrency ? CurrencyManager.Instance.GetCurrencyAmountFromCredits(currentPrice) : currentPrice);
				int currentLevel = upgrade.GetCurrentLevel();
				int num2 = currentLevel + upgrade.GetRemainingLevels();
				bool flag = upgrade.GetRemainingLevels() == 0;
				bool flag2 = num <= currencyAmount;
				Plugin.ExtendedLogging("Init Upgrade: " + upgrade.Name, (LogLevel)16);
				GameObject val = Object.Instantiate<GameObject>(Plugin.UpgradeButton, mainScrollContent);
				Plugin.ApplyFontTo(val);
				Button component = ((Component)val.transform.Find("Button")).GetComponent<Button>();
				TMP_Text component2 = ((Component)((Component)component).transform.Find("Text (TMP)")).GetComponent<TMP_Text>();
				component2.text = $"{upgrade.Name} : {currentLevel}/{num2}";
				((Graphic)component2).color = (flag2 ? NormalTextColor : RedTextColor);
				if (flag2 && !flag && upgrade.SalePercentage < 1f)
				{
					((Graphic)component2).color = SaleColor;
				}
				TMP_Text component3 = ((Component)val.transform.Find("DisplayText")).GetComponent<TMP_Text>();
				((Graphic)component3).color = (flag2 ? NormalTextColor : RedTextColor);
				if (flag2 && !flag && upgrade.SalePercentage < 1f)
				{
					((Graphic)component3).color = SaleColor;
				}
				TMP_Text component4 = ((Component)val.transform.Find("DisplayText/PointsRequired")).GetComponent<TMP_Text>();
				if (flag)
				{
					component4.text = "Maxed";
				}
				else if (upgrade.SalePercentage < 1f)
				{
					float num3 = (1f - upgrade.SalePercentage) * 100f;
					component4.text = $"{num} ({Mathf.RoundToInt(num3)}% off)";
				}
				else
				{
					component4.text = num.ToString();
				}
				((Graphic)component4).color = (flag2 ? NormalTextColor : RedTextColor);
				if (flag2 && !flag && upgrade.SalePercentage < 1f)
				{
					((Graphic)component4).color = SaleColor;
				}
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					swapTwo(purchase: true);
					showUpgradeGui(upgrade);
				});
			}
		}

		public static void showSettingsMenu(bool settings)
		{
			mainScreen.gameObject.SetActive(!settings);
			settingsScreen.gameObject.SetActive(settings);
		}

		public void refresh(bool trade = false)
		{
			if ((Object)(object)menu == (Object)null || !menu.activeInHierarchy)
			{
				return;
			}
			if (trade)
			{
				if (location == "showUpgrades," + false)
				{
					showUpgrades(shared: false);
				}
				if (location == "showTradeGui")
				{
					showTradeGui();
				}
			}
			if (location == "showUpgrades," + true)
			{
				showUpgrades(shared: true);
			}
			if (location == "showUpgradeGui" && currentSelection != null)
			{
				showUpgradeGui(currentSelection);
			}
		}

		public static void showUpgradeGui(CustomTerminalNode currentUpgrade)
		{
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			currentSelection = currentUpgrade;
			location = "showUpgradeGui";
			TextMeshProUGUI component = ((Component)menu.transform.Find("Background/PurchaseUpgrade/Text (TMP)")).GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).text = currentUpgrade.Description;
			Button component2 = ((Component)menu.transform.Find("Background/PurchaseUpgrade/PurchaseButton")).GetComponent<Button>();
			Button component3 = ((Component)menu.transform.Find("Background/PurchaseUpgrade/BackButton")).GetComponent<Button>();
			int currentPrice = currentUpgrade.GetCurrentPrice();
			int effectivePrice = (currentUpgrade.AlternateCurrency ? CurrencyManager.Instance.GetCurrencyAmountFromCredits(currentPrice) : currentPrice);
			string text = ((currentPrice != int.MaxValue) ? ("Purchase: " + effectivePrice) : "Maxed");
			((Selectable)component2).interactable = CurrencyManager.Instance.CurrencyAmount >= effectivePrice;
			TMP_Text component4 = ((Component)((Component)component2).transform.Find("Text (TMP)")).GetComponent<TMP_Text>();
			component4.text = text;
			((Graphic)component4).color = (((Selectable)component2).interactable ? NormalTextColor : RedTextColor);
			((UnityEventBase)component2.onClick).RemoveAllListeners();
			((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
			{
				Plugin.ExtendedLogging("Purchasing Upgrade: " + currentUpgrade.Name, (LogLevel)16);
				if (currentUpgrade.AlternateCurrency)
				{
					CurrencyManager instance = CurrencyManager.Instance;
					instance.CurrencyAmount -= effectivePrice;
				}
				UpgradeApi.TriggerUpgradeRankup(currentUpgrade);
				currencyText.text = CurrencyManager.Instance.CurrencyAmount.ToString();
				showUpgradeGui(currentUpgrade);
			});
			((UnityEventBase)component3.onClick).RemoveAllListeners();
			((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
			{
				showUpgrades(currentUpgrade.SharedUpgrade);
			});
		}

		public static void showAdminGui()
		{
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			currentSelection = null;
			location = "showAdminGui";
			swapTwo(purchase: false);
			int currencyAmount = CurrencyManager.Instance.CurrencyAmount;
			currencyText.text = currencyAmount.ToString();
			clearMainViewport();
			ulong myID = StartOfRound.Instance.localPlayerController.actualClientId;
			foreach (PlayerControllerB item in StartOfRound.Instance.allPlayerScripts.OrderBy((PlayerControllerB p) => p.playerUsername))
			{
				if (!item.isPlayerControlled && !item.isPlayerDead)
				{
					continue;
				}
				GameObject val = Object.Instantiate<GameObject>(Plugin.TradePrefab, mainScrollContent);
				Plugin.ApplyFontTo(val);
				Button component = ((Component)val.transform.Find("Button")).GetComponent<Button>();
				((Component)((Component)component).transform.Find("Text (TMP)")).GetComponent<TMP_Text>().text = "Add Points";
				Button component2 = ((Component)val.transform.Find("Button")).GetComponent<Button>();
				TMP_InputField input = ((Component)val.transform.Find("InputField (TMP)")).GetComponent<TMP_InputField>();
				TMP_Text component3 = ((Component)val.transform.Find("InputField (TMP)/DisplayText")).GetComponent<TMP_Text>();
				component3.text = item.playerUsername;
				bool isUpdating = false;
				ulong targetPlayerID = item.actualClientId;
				((UnityEvent<string>)(object)input.onValueChanged).AddListener((UnityAction<string>)delegate(string text)
				{
					if (!isUpdating)
					{
						if (int.TryParse(text, out var result))
						{
							int num = Mathf.Clamp(result, -99, 9999);
							if (num.ToString() != text)
							{
								isUpdating = true;
								input.text = num.ToString();
								isUpdating = false;
							}
						}
						else
						{
							isUpdating = true;
							input.text = "0";
							isUpdating = false;
						}
					}
				});
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					CurrencyManager.Instance.TradePlayerCreditsServerRpc(targetPlayerID, int.Parse(input.text), default(ServerRpcParams));
					if (targetPlayerID == myID)
					{
						showAdminGui();
					}
				});
			}
		}

		public static void showTradeGui()
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Expected O, but got Unknown
			currentSelection = null;
			location = "showTradeGui";
			swapTwo(purchase: false);
			int currency = CurrencyManager.Instance.CurrencyAmount;
			currencyText.text = currency.ToString();
			clearMainViewport();
			foreach (PlayerControllerB item in StartOfRound.Instance.allPlayerScripts.OrderBy((PlayerControllerB p) => p.playerUsername))
			{
				if ((Object)(object)StartOfRound.Instance.localPlayerController == (Object)(object)item || (!item.isPlayerControlled && !item.isPlayerDead))
				{
					continue;
				}
				GameObject val = Object.Instantiate<GameObject>(Plugin.TradePrefab, mainScrollContent);
				Plugin.ApplyFontTo(val);
				Button tradeButton = ((Component)val.transform.Find("Button")).GetComponent<Button>();
				TMP_InputField tradeInput = ((Component)val.transform.Find("InputField (TMP)")).GetComponent<TMP_InputField>();
				TMP_Text component = ((Component)val.transform.Find("InputField (TMP)/DisplayText")).GetComponent<TMP_Text>();
				component.text = item.playerUsername;
				bool isUpdating = false;
				((Selectable)tradeButton).interactable = false;
				ulong targetPlayerID = item.actualClientId;
				((UnityEvent<string>)(object)tradeInput.onValueChanged).AddListener((UnityAction<string>)delegate(string text)
				{
					if (!isUpdating)
					{
						if (int.TryParse(text, out var result))
						{
							int num = Mathf.Clamp(result, 0, currency);
							if (num.ToString() != text)
							{
								isUpdating = true;
								tradeInput.text = num.ToString();
								isUpdating = false;
							}
							((Selectable)tradeButton).interactable = num != 0;
						}
						else
						{
							isUpdating = true;
							tradeInput.text = "0";
							isUpdating = false;
						}
					}
				});
				((UnityEvent)tradeButton.onClick).AddListener((UnityAction)delegate
				{
					//IL_0040: Unknown result type (might be due to invalid IL or missing references)
					//IL_0046: Unknown result type (might be due to invalid IL or missing references)
					CurrencyManager instance = CurrencyManager.Instance;
					instance.CurrencyAmount -= int.Parse(tradeInput.text);
					CurrencyManager.Instance.TradePlayerCreditsServerRpc(targetPlayerID, int.Parse(tradeInput.text), default(ServerRpcParams));
					showTradeGui();
				});
			}
		}
	}
	public class MenuController : MonoBehaviour
	{
		private InputAction escAction;

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Plugin.ExtendedLogging("Setting up Escape Action", (LogLevel)16);
			escAction = new InputAction((string)null, (InputActionType)0, "<Keyboard>/escape", (string)null, (string)null, (string)null);
			escAction.performed += delegate
			{
				CloseMenu();
			};
			escAction.Enable();
		}

		public void Reopen()
		{
			InputAction obj = escAction;
			if (obj != null)
			{
				obj.Enable();
			}
		}

		private void OnDestroy()
		{
			Plugin.ExtendedLogging("OnDestroy", (LogLevel)16);
			InputAction obj = escAction;
			if (obj != null)
			{
				obj.Disable();
			}
			InputAction obj2 = escAction;
			if (obj2 != null)
			{
				obj2.Dispose();
			}
		}

		public void CloseMenu()
		{
			Plugin.ExtendedLogging("Closing Menu", (LogLevel)16);
			if ((Object)(object)PurchaseMenu.menu != (Object)null)
			{
				Cursor.visible = false;
				Cursor.lockState = (CursorLockMode)1;
				StartOfRound.Instance.localPlayerController.quickMenuManager.isMenuOpen = false;
				InputAction obj = escAction;
				if (obj != null)
				{
					obj.Disable();
				}
				if ((Object)(object)PurchaseMenu.fader != (Object)null)
				{
					Plugin.ExtendedLogging("Fader", (LogLevel)16);
					PurchaseMenu.fader.FadeOut();
				}
				else
				{
					Plugin.ExtendedLogging("No Fader found??", (LogLevel)16);
					PurchaseMenu.menu.SetActive(false);
				}
			}
		}
	}
	public class UIFadeEffect : MonoBehaviour
	{
		public List<Graphic> graphics;

		private void Awake()
		{
			graphics = new List<Graphic>(((Component)this).GetComponentsInChildren<Graphic>(true));
		}

		public void doFade(GameObject target, bool fadeOut)
		{
			((MonoBehaviour)this).StartCoroutine(FadeObject(target, fadeOut));
		}

		private IEnumerator FadeObject(GameObject fadeObj, bool fadeOut)
		{
			List<Graphic> graphicsToUse = new List<Graphic>(fadeObj.GetComponentsInChildren<Graphic>(true));
			float startAlpha = 0f;
			float endAlpha = Plugin.transparency.Value;
			if (fadeOut)
			{
				startAlpha = Plugin.transparency.Value;
				endAlpha = 0f;
			}
			float fadeDuration = Plugin.openSpeed.Value;
			float time = 0f;
			while (time < fadeDuration)
			{
				float t = time / fadeDuration;
				float alpha = Mathf.Lerp(startAlpha, endAlpha, t);
				SetAlpha(graphicsToUse, alpha);
				time += Time.unscaledDeltaTime;
				yield return null;
			}
			foreach (Graphic g in graphicsToUse)
			{
				if ((Object)(object)g != (Object)null)
				{
					Color c = g.color;
					c.a = endAlpha;
					g.color = c;
				}
			}
			if (fadeOut && endAlpha == 0f)
			{
				fadeObj.SetActive(false);
				StartOfRound.Instance.localPlayerController.quickMenuManager.isMenuOpen = false;
			}
		}

		public void FadeIn()
		{
			((MonoBehaviour)this).StartCoroutine(Fade(0f, Plugin.transparency.Value));
		}

		public void FadeOut(bool disableAfter = true)
		{
			((MonoBehaviour)this).StartCoroutine(Fade(1f, 0f, disableAfter));
		}

		private void SetAlpha(List<Graphic> graphicsToUse, float alpha)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			foreach (Graphic item in graphicsToUse)
			{
				if ((Object)(object)item != (Object)null)
				{
					Color color = item.color;
					color.a = alpha;
					item.color = color;
				}
			}
		}

		private IEnumerator Fade(float startAlpha, float endAlpha, bool disableAfter = false)
		{
			graphics = new List<Graphic>(((Component)this).GetComponentsInChildren<Graphic>(true));
			float fadeDuration = Plugin.openSpeed.Value;
			float time = 0f;
			while (time < fadeDuration)
			{
				float t = time / fadeDuration;
				SetAlpha(alpha: Mathf.Lerp(startAlpha, endAlpha, t), graphicsToUse: graphics);
				time += Time.unscaledDeltaTime;
				yield return null;
			}
			foreach (Graphic g in graphics)
			{
				if ((Object)(object)g != (Object)null)
				{
					Color c = g.color;
					c.a = endAlpha;
					g.color = c;
				}
			}
			if (disableAfter && endAlpha == 0f)
			{
				((Component)this).gameObject.SetActive(false);
				StartOfRound.Instance.localPlayerController.quickMenuManager.isMenuOpen = false;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LGUGui";

		public const string PLUGIN_NAME = "LGUGui";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}