UI.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Character_Stats;
using HarmonyLib;
using Improve;
using Increase_Tumble_Damage;
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 = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("headclef")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+7de10e98507474cb1db45c2550529860e445c29f")]
[assembly: AssemblyProduct("UI")]
[assembly: AssemblyTitle("UI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 HeadclefUI
{
	[BepInPlugin("headclef.UI", "UI", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class HeadclefUI : BaseUnityPlugin
	{
		private const string PluginGuid = "headclef.UI";

		private const string PluginName = "UI";

		private const string PluginVersion = "1.1.1";

		internal static HeadclefUI Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0041: 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)
			//IL_0048: Expected O, but got Unknown
			//IL_004d: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void OnDestroy()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class MapValueTracker
	{
		private static float _lastRecalcTime;

		private const float RecalcInterval = 2f;

		public static float TotalValue { get; private set; }

		public static float InitialValue { get; private set; }

		public static void Reset()
		{
			TotalValue = 0f;
			InitialValue = 0f;
			_lastRecalcTime = 0f;
		}

		public static void Recalculate()
		{
			if ((Object)(object)RoundDirector.instance == (Object)null || Traverse.Create((object)RoundDirector.instance).Field("allExtractionPointsCompleted").GetValue<bool>())
			{
				return;
			}
			TotalValue = 0f;
			ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>();
			ValuableObject[] array2 = array;
			foreach (ValuableObject val in array2)
			{
				if (val.dollarValueSet)
				{
					TotalValue += val.dollarValueCurrent;
				}
			}
			_lastRecalcTime = Time.time;
		}

		public static void UpdateIfNeeded()
		{
			if (Time.time - _lastRecalcTime >= 2f)
			{
				Recalculate();
			}
		}

		[HarmonyPatch(typeof(LevelGenerator), "StartRoomGeneration")]
		[HarmonyPrefix]
		private static void OnGenerationStart()
		{
			Reset();
		}

		[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
		[HarmonyPostfix]
		private static void OnGenerationDone()
		{
			Recalculate();
			InitialValue = TotalValue;
		}

		[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "BreakRPC")]
		[HarmonyPostfix]
		private static void OnBreak(float valueLost, bool _loseValue)
		{
			if (_loseValue)
			{
				TotalValue -= valueLost;
			}
		}

		[HarmonyPatch(typeof(PhysGrabObject), "DestroyPhysGrabObjectRPC")]
		[HarmonyPostfix]
		private static void OnDestroy(PhysGrabObject __instance)
		{
			if (SemiFunc.RunIsLevel())
			{
				ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
				if (!((Object)(object)component == (Object)null) && component.dollarValueCurrent >= component.dollarValueOriginal * 0.15f)
				{
					TotalValue -= component.dollarValueCurrent;
				}
			}
		}

		[HarmonyPatch(typeof(RoundDirector), "ExtractionCompleted")]
		[HarmonyPostfix]
		private static void OnExtraction()
		{
			if (SemiFunc.RunIsLevel())
			{
				Recalculate();
			}
		}
	}
	[HarmonyPatch]
	public static class TabOverlay
	{
		private static GameObject? _overlayRoot;

		private static TextMeshProUGUI? _overlayText;

		[HarmonyPatch(typeof(RoundDirector), "Update")]
		[HarmonyPostfix]
		private static void RoundDirector_Update_Postfix()
		{
			if (!SemiFunc.RunIsLevel())
			{
				return;
			}
			try
			{
				if ((Object)(object)_overlayRoot == (Object)null)
				{
					_overlayRoot = null;
					_overlayText = null;
					CreateOverlay();
					if ((Object)(object)_overlayRoot == (Object)null)
					{
						return;
					}
				}
				bool flag = false;
				if ((Object)(object)MapToolController.instance != (Object)null)
				{
					flag = Traverse.Create((object)MapToolController.instance).Field("mapToggled").GetValue<bool>();
				}
				bool flag2 = SemiFunc.InputHold((InputKey)8) || flag;
				_overlayRoot.SetActive(flag2);
				if (flag2)
				{
					UpdateContent();
				}
			}
			catch (Exception ex)
			{
				HeadclefUI.Logger.LogError((object)("TabOverlay exception: " + ex.Message));
			}
		}

		[HarmonyPatch(typeof(SemiFunc), "OnSceneSwitch")]
		[HarmonyPrefix]
		private static void OnSceneSwitch_Prefix()
		{
			if ((Object)(object)_overlayRoot != (Object)null)
			{
				Object.Destroy((Object)(object)_overlayRoot);
				_overlayRoot = null;
				_overlayText = null;
			}
		}

		private static void CreateOverlay()
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Game Hud");
			if ((Object)(object)val == (Object)null)
			{
				HeadclefUI.Logger.LogWarning((object)"Tab overlay: 'Game Hud' not found.");
				return;
			}
			GameObject val2 = GameObject.Find("Tax Haul");
			if ((Object)(object)val2 == (Object)null)
			{
				HeadclefUI.Logger.LogWarning((object)"Tab overlay: 'Tax Haul' not found.");
				return;
			}
			TMP_FontAsset font = val2.GetComponent<TMP_Text>().font;
			HeadclefUI.Logger.LogInfo((object)("CreateOverlay: gameHud='" + ((Object)val).name + "', font='" + ((font != null) ? ((Object)font).name : null) + "'"));
			_overlayRoot = new GameObject();
			_overlayRoot.SetActive(false);
			((Object)_overlayRoot).name = "Headclef Tab Overlay";
			_overlayRoot.AddComponent<TextMeshProUGUI>();
			_overlayText = _overlayRoot.GetComponent<TextMeshProUGUI>();
			((TMP_Text)_overlayText).font = font;
			((Graphic)_overlayText).color = new Color(0.79f, 0.91f, 0.9f, 1f);
			((TMP_Text)_overlayText).fontSize = 18f;
			((TMP_Text)_overlayText).enableWordWrapping = true;
			((TMP_Text)_overlayText).alignment = (TextAlignmentOptions)260;
			((TMP_Text)_overlayText).horizontalAlignment = (HorizontalAlignmentOptions)4;
			((TMP_Text)_overlayText).verticalAlignment = (VerticalAlignmentOptions)256;
			_overlayRoot.transform.SetParent(val.transform, false);
			RectTransform component = _overlayRoot.GetComponent<RectTransform>();
			component.pivot = new Vector2(1f, 1f);
			component.anchoredPosition = new Vector2(1f, -1f);
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 0f);
			component.sizeDelta = new Vector2(0f, 0f);
			component.offsetMax = new Vector2(0f, 350f);
			component.offsetMin = new Vector2(400f, 150f);
			ManualLogSource logger = HeadclefUI.Logger;
			object arg = _overlayRoot.activeInHierarchy;
			Transform parent = _overlayRoot.transform.parent;
			logger.LogInfo((object)$"Overlay created. activeInHierarchy={arg}, parent='{((parent != null) ? ((Object)parent).name : null)}'");
			HeadclefUI.Logger.LogInfo((object)$"isDestroyed check: rootNull={(Object)(object)_overlayRoot == (Object)null}, refNull={_overlayRoot == null}");
		}

		private static void UpdateContent()
		{
			if ((Object)(object)_overlayText == (Object)null)
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine();
			stringBuilder.AppendLine();
			int num = 0;
			if (StatsManager.instance?.runStats != null && StatsManager.instance.runStats.ContainsKey("level"))
			{
				num = StatsManager.instance.runStats["level"] + 1;
			}
			stringBuilder.AppendLine($"<color=#ff9600><size=22><b>Map Level {num}</b></size></color>");
			try
			{
				int num2 = SaveData.CurrentLevel();
				int num3 = SaveData.AvailablePoints();
				stringBuilder.AppendLine($"<color=#00ff99><size=22><b>Improve Level {num2}</b></size></color>");
				stringBuilder.AppendLine($"<color=#cccccc>Available Points:</color> <color=#ffffff>{num3}</color>");
			}
			catch
			{
			}
			MapValueTracker.UpdateIfNeeded();
			float totalValue = MapValueTracker.TotalValue;
			stringBuilder.AppendLine($"<color=#aaaaaa>Map Value:</color> <color=#55ff55>${totalValue:N0}</color>");
			if ((Object)(object)RoundDirector.instance != (Object)null)
			{
				int value = Traverse.Create((object)RoundDirector.instance).Field("extractionHaulGoal").GetValue<int>();
				int currentHaul = RoundDirector.instance.currentHaul;
				if (value > 0)
				{
					float num4 = (float)currentHaul / (float)value * 100f;
					string arg = ((num4 >= 100f) ? "#55ff55" : ((num4 >= 50f) ? "#ffff55" : "#ff5555"));
					stringBuilder.AppendLine($"<color=#aaaaaa>Haul:</color> <color={arg}>${currentHaul:N0} / ${value:N0}</color>");
				}
			}
			stringBuilder.AppendLine("<color=#ff9600><b>Combat</b></color>");
			AppendCombatInfo(stringBuilder);
			stringBuilder.AppendLine("<color=#ff9600><b>Players</b></color>");
			List<PlayerAvatar> list = SemiFunc.PlayerGetAll();
			if (list != null)
			{
				foreach (PlayerAvatar item in list)
				{
					if (!((Object)(object)item == (Object)null))
					{
						string text = item.playerName ?? "Unknown";
						string text2;
						string text3;
						if (item.deadSet)
						{
							text2 = "Dead";
							text3 = "#ff5555";
						}
						else
						{
							text2 = "Alive";
							text3 = "#55ff55";
						}
						stringBuilder.AppendLine("  <color=#cccccc>" + text + "</color> — <color=" + text3 + ">" + text2 + "</color>");
					}
				}
			}
			((TMP_Text)_overlayText).text = stringBuilder.ToString();
		}

		private static void AppendCombatInfo(StringBuilder sb)
		{
			ItemGun heldGun = GetHeldGun();
			if ((Object)(object)heldGun != (Object)null)
			{
				int num = (((Object)(object)heldGun.itemBattery != (Object)null) ? heldGun.itemBattery.currentBars : 0);
				int num2 = (((Object)(object)heldGun.itemBattery != (Object)null) ? heldGun.itemBattery.batteryBars : 0);
				int gunDamage = GetGunDamage(heldGun);
				string arg = ((num > 0) ? "#55ff55" : "#ff5555");
				sb.AppendLine("  <color=#aaaaaa>Weapon:</color> <color=#cccccc>" + ((Object)((Component)heldGun).gameObject).name + "</color>");
				sb.AppendLine($"  <color=#aaaaaa>Ammo:</color> <color={arg}>{num} / {num2}</color>");
				sb.AppendLine($"  <color=#aaaaaa>Damage:</color> <color=#ffaa55>{gunDamage}</color>");
			}
			else
			{
				int tumbleLaunchDamage = GetTumbleLaunchDamage();
				if (tumbleLaunchDamage > 0)
				{
					sb.AppendLine($"  <color=#aaaaaa>Tumble Launch:</color> <color=#ffaa55>{tumbleLaunchDamage} dmg</color>");
				}
				else
				{
					sb.AppendLine("  <color=#666666>No weapon held</color>");
				}
			}
		}

		private static ItemGun? GetHeldGun()
		{
			try
			{
				PhysGrabber instance = PhysGrabber.instance;
				if ((Object)(object)instance != (Object)null && instance.grabbed && (Object)(object)instance.grabbedPhysGrabObject != (Object)null)
				{
					PhysGrabObject grabbedPhysGrabObject = instance.grabbedPhysGrabObject;
					ItemGun val = ((Component)grabbedPhysGrabObject).GetComponent<ItemGun>() ?? ((Component)grabbedPhysGrabObject).GetComponentInChildren<ItemGun>();
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				ItemGun[] array = Object.FindObjectsOfType<ItemGun>();
				foreach (ItemGun val2 in array)
				{
					PhysGrabObject val3 = ((Component)val2).GetComponent<PhysGrabObject>() ?? ((Component)val2).GetComponentInParent<PhysGrabObject>();
					if ((Object)(object)val3 != (Object)null && val3.grabbedLocal)
					{
						return val2;
					}
				}
				return null;
			}
			catch
			{
				return null;
			}
		}

		private static int GetGunDamage(ItemGun gun)
		{
			try
			{
				if ((Object)(object)gun.bulletPrefab != (Object)null)
				{
					ItemGunBullet component = gun.bulletPrefab.GetComponent<ItemGunBullet>();
					if ((Object)(object)component != (Object)null && component.hasHurtCollider && (Object)(object)component.hurtCollider != (Object)null)
					{
						return component.hurtCollider.enemyDamage;
					}
				}
				ItemGunLaser val = ((Component)gun).GetComponent<ItemGunLaser>() ?? ((Component)gun).GetComponentInChildren<ItemGunLaser>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.semiLaser != (Object)null && (Object)(object)val.semiLaser.hurtCollider != (Object)null)
				{
					return val.semiLaser.hurtCollider.enemyDamage;
				}
				if ((Object)(object)gun.hurtCollider != (Object)null)
				{
					return gun.hurtCollider.enemyDamage;
				}
			}
			catch
			{
			}
			return 0;
		}

		private static int GetTumbleLaunchDamage()
		{
			try
			{
				if ((Object)(object)PlayerAvatar.instance == (Object)null)
				{
					return 0;
				}
				PlayerTumble tumble = PlayerAvatar.instance.tumble;
				if ((Object)(object)tumble == (Object)null)
				{
					return 0;
				}
				HurtCollider hurtCollider = tumble.hurtCollider;
				if ((Object)(object)hurtCollider == (Object)null)
				{
					return 0;
				}
				int num = hurtCollider.enemyDamage;
				if (num <= 0)
				{
					num = 12;
				}
				string text = SemiFunc.PlayerGetSteamID(PlayerAvatar.instance);
				int num2 = 0;
				try
				{
					num2 = Character_Stats.GetUpgradeLevel(text, "Launch");
				}
				catch
				{
					if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.playerUpgradeLaunch.TryGetValue(text, out var value))
					{
						num2 = value;
					}
				}
				if (num2 > 0 && Increase_Tumble_Damage.EnableDamageOnEnemy.Value)
				{
					float value2 = Increase_Tumble_Damage.MultiplierPerLevel.Value;
					float value3 = Increase_Tumble_Damage.MaxMultiplier.Value;
					float num3 = value2 * (float)num2;
					if (value3 > 0f)
					{
						num3 = Math.Min(num3, value3);
					}
					if (num3 > 0f)
					{
						return Mathf.RoundToInt((float)num * num3);
					}
				}
				return num;
			}
			catch
			{
				return 0;
			}
		}
	}
}