Decompiled source of ShipGrabbableStat v1.0.7

ShipGrabbableStat.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ShipGrabbableStat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("ShipGrabbableStat")]
[assembly: AssemblyCopyright("Copyright © tinymins 2023")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.7")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.0")]
[module: UnverifiableCode]
namespace ShipGrabbableStat
{
	[BepInPlugin("com.zhaiyiming.github.tinymins.ShipGrabbableStat", "ShipGrabbableStat", "1.0.7")]
	internal class ShipGrabbableStat : BaseUnityPlugin
	{
		public const string GUID = "com.zhaiyiming.github.tinymins.ShipGrabbableStat";

		public const string NAME = "ShipGrabbableStat";

		public const string VERSION = "1.0.7";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> StatGrabbables;

		internal static ConfigEntry<bool> HideZeroItems;

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			StatGrabbables = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "StatGrabbables", "Walkie-talkie::Walkie-talkie,Flashlight,Shovel,Lockpicker,Pro-flashlight,Stun grenade,Boombox,TZP-Inhalant,Zap gun,Jetpack,Extension ladder,Radar-booster,Spray paint,Rocket Launcher,Flaregun,Emergency Flare (ammo),Toy Hammer,Remote Radar,Utility Belt,Hacking Tool,Pinger,Portable Tele,Advanced Portable Tele,Night Vision Goggles,Medkit,Peeper,Helmet,Diving Kit,Wheelbarrow,Ouija Board,Shells,Key,Fire Axe", "Grabbable names which will be stated while scan in ship, splitted by \",\", use \"::\" to set name alias for display.");
			HideZeroItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "HideZeroItems", true, "Hide grabbable item stat if its count is zero.");
			new Harmony("com.zhaiyiming.github.tinymins.ShipGrabbableStat").PatchAll(Assembly.GetExecutingAssembly());
		}
	}
}
namespace ShipGrabbableStat.Patches
{
	[HarmonyPatch]
	internal class HUDManagerPatcher
	{
		private static GameObject _shipGrabbableCounter;

		private static TextMeshProUGUI _textMesh;

		private static float _displayTimeLeft;

		private const float DisplayTime = 5f;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(HUDManager), "PingScan_performed")]
		private static void OnScan(HUDManager __instance, CallbackContext context)
		{
			if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && ((CallbackContext)(ref context)).performed && __instance.CanPlayerScan() && !(__instance.playerPingingScan > -0.5f) && (StartOfRound.Instance.inShipPhase || GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom))
			{
				if (!Object.op_Implicit((Object)(object)_shipGrabbableCounter))
				{
					CopyValueCounter();
				}
				((TMP_Text)_textMesh).text = CalculateGrabbableStatText();
				_displayTimeLeft = 5f;
				if (!_shipGrabbableCounter.activeSelf)
				{
					((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(ShipGrabbableStatCoroutine());
				}
			}
		}

		private static IEnumerator ShipGrabbableStatCoroutine()
		{
			_shipGrabbableCounter.SetActive(true);
			while (_displayTimeLeft > 0f)
			{
				float displayTimeLeft = _displayTimeLeft;
				_displayTimeLeft = 0f;
				yield return (object)new WaitForSeconds(displayTimeLeft);
			}
			_shipGrabbableCounter.SetActive(false);
		}

		private static string CalculateGrabbableStatText()
		{
			List<GrabbableObject> source = GameObject.Find("/Environment/HangarShip").GetComponentsInChildren<GrabbableObject>().ToList();
			StringBuilder stringBuilder = new StringBuilder();
			foreach (string[] item in from i in ShipGrabbableStat.StatGrabbables.Value.Split(new char[1] { ',' })
				select i.Trim().Split(new string[1] { "::" }, StringSplitOptions.None))
			{
				string itemName = item[0];
				string arg = ((item.Length > 1) ? item[1] : item[0]);
				int num = source.Count((GrabbableObject item) => item.itemProperties.itemName == itemName);
				if (num != 0 || !ShipGrabbableStat.HideZeroItems.Value)
				{
					stringBuilder.AppendLine($"{arg} x{num}");
				}
			}
			return stringBuilder.ToString();
		}

		private static void CopyValueCounter()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			string text = string.Join(", ", StartOfRound.Instance.allItemsList.itemsList.Select((Item item) => item.itemName ?? "").ToList());
			ShipGrabbableStat.Log.LogDebug((object)("List all items: " + text));
			GameObject obj = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/BottomMiddle/ValueCounter");
			if (!Object.op_Implicit((Object)(object)obj))
			{
				ShipGrabbableStat.Log.LogError((object)"Failed to find ValueCounter object to copy!");
			}
			GameObject val = GameObject.Find("/Systems/UI/Canvas/IngamePlayerHUD/TopRightCorner");
			if (!Object.op_Implicit((Object)(object)val))
			{
				ShipGrabbableStat.Log.LogError((object)"Failed to find TopRightCorner object to paste!");
			}
			_shipGrabbableCounter = Object.Instantiate<GameObject>(obj.gameObject, val.transform, false);
			Vector3 localPosition = _shipGrabbableCounter.transform.localPosition;
			_shipGrabbableCounter.transform.localPosition = new Vector3(localPosition.x - 25f, -15f, localPosition.z);
			_textMesh = _shipGrabbableCounter.GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)_textMesh).fontSize = 18f;
			((TMP_Text)_textMesh).alignment = (TextAlignmentOptions)260;
			Image componentInChildren = _shipGrabbableCounter.GetComponentInChildren<Image>();
			if (componentInChildren != null)
			{
				((Component)componentInChildren).gameObject.SetActive(false);
			}
		}
	}
}