Decompiled source of AutoScan v0.5.0

AutoScan.dll

Decompiled 11 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using AutoScan.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
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: AssemblyTitle("AutoScan")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoScan")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dac61a79-d5f7-4701-af89-732fa8ee54c8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoScan
{
	internal class ConfigSettings
	{
		public static ConfigEntry<bool> EnableHUDScan { get; set; }

		public static ConfigEntry<bool> EnableScanInChat { get; set; }

		public static ConfigEntry<string> HUDColor { get; set; }

		public static void Init()
		{
			EnableHUDScan = ((BaseUnityPlugin)AutoScanBase.Instance).Config.Bind<bool>("Enable scan data on hud", "EnableHUDScan", true, "Enable or disable the scan on your HUD");
			EnableScanInChat = ((BaseUnityPlugin)AutoScanBase.Instance).Config.Bind<bool>("Enable scan data in chat", "EnableHUDScan", true, "Enable or disable scan data sent in your chat");
		}
	}
	internal class Outil
	{
		public static string TextScanForChatTemplate = "S : {0} | Val : {1}";

		public static string TextScanForHUDTemplate = "S:{0} | Val:{1}";

		public static void CalculateAndDisplayScan()
		{
			int num = 0;
			int num2 = 0;
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].itemProperties.isScrap && !array[i].isInShipRoom && !array[i].isInElevator)
				{
					num++;
					num2 += array[i].scrapValue;
				}
			}
			AutoScanBase.Log("valueItems : " + num2);
			if (ConfigSettings.EnableScanInChat.Value)
			{
				HUDManager.Instance.AddTextToChatOnServer(string.Format(TextScanForChatTemplate, num, num2), -1);
			}
			if (ConfigSettings.EnableHUDScan.Value)
			{
				HUDManagerPatches.SetScanText(string.Format(TextScanForHUDTemplate, num.ToString().PadLeft(2, ' '), num2.ToString().PadLeft(3, ' ')));
			}
		}

		public static object GetColor32FromHexColor(string hexColorstr)
		{
			hexColorstr = ConfigSettings.HUDColor.Value.Replace("#", "");
			if (hexColorstr.Length != 6)
			{
				return null;
			}
			string[] array = new string[3];
			int num = 0;
			for (int i = 0; i < hexColorstr.Length; i++)
			{
				array[num] += hexColorstr[i];
				if ((i + 1) % 2 == 0)
				{
					num++;
				}
			}
			return null;
		}
	}
	[BepInPlugin("Matsuura.AutoScan", "AutoScan", "0.5.0")]
	public class AutoScanBase : BaseUnityPlugin
	{
		private const string modGUID = "Matsuura.AutoScan";

		private const string modName = "AutoScan";

		private const string modVersion = "0.5.0";

		private readonly Harmony _harmony = new Harmony("Matsuura.AutoScan");

		public static AutoScanBase Instance;

		private static ManualLogSource _logSource;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			if (_logSource == null)
			{
				_logSource = Logger.CreateLogSource("Matsuura.AutoScan");
			}
			ConfigSettings.Init();
			_harmony.PatchAll();
			_logSource.LogInfo((object)"AutoScan Awake");
		}

		internal static void Log(string message)
		{
			if (_logSource != null)
			{
				_logSource.LogInfo((object)message);
			}
		}

		internal static void LogD(string message)
		{
			if (_logSource != null)
			{
				_logSource.LogDebug((object)message);
			}
		}
	}
}
namespace AutoScan.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatches
	{
		private static TextMeshProUGUI _scanText;

		private static readonly Color DefaultColor = Color32.op_Implicit(new Color32((byte)0, byte.MaxValue, (byte)0, byte.MaxValue));

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ref HUDManager __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigSettings.EnableHUDScan.Value)
			{
				GameObject val = new GameObject("ScanHUDDisplay");
				val.AddComponent<RectTransform>();
				TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
				RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
				((Transform)rectTransform).SetParent(((Component)__instance.PTTIcon).transform, false);
				rectTransform.anchoredPosition = new Vector2(1.6f, -110.7f);
				((TMP_Text)val2).font = ((TMP_Text)__instance.controlTipLines[0]).font;
				((TMP_Text)val2).fontSize = 11f;
				((TMP_Text)val2).text = "";
				((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
				((Behaviour)val2).enabled = true;
				Color defaultColor = DefaultColor;
				((Graphic)val2).color = defaultColor;
				_scanText = val2;
			}
		}

		public static void SetScanText(string text)
		{
			if ((Object)(object)_scanText != (Object)null)
			{
				((TMP_Text)_scanText).text = text;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatches
	{
		[HarmonyPatch("SetItemInElevator")]
		[HarmonyPostfix]
		public static void SetItemInElevator(bool droppedInShipRoom, bool droppedInElevator, GrabbableObject gObject)
		{
			AutoScanBase.Log("droppedInShipRoom : " + droppedInShipRoom);
			if (droppedInShipRoom)
			{
				Outil.CalculateAndDisplayScan();
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatches
	{
		[HarmonyPatch("OpenShipDoors")]
		[HarmonyPostfix]
		public static void OpenShipDoors()
		{
			AutoScanBase.Log("StartOfRound.Instance.inShipPhase : " + StartOfRound.Instance.inShipPhase);
			CalculateAsync();
		}

		public static async void CalculateAsync()
		{
			await Task.Delay(5000);
			Outil.CalculateAndDisplayScan();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatches
	{
		[HarmonyPatch("TextPostProcess")]
		[HarmonyPrefix]
		private static void TextPostProcess(string modifiedDisplayText, TerminalNode node)
		{
			if (modifiedDisplayText.Contains("[scanForItems]"))
			{
				Outil.CalculateAndDisplayScan();
			}
		}
	}
}