Decompiled source of ScannerFix v1.2.0

plugins/ScannerFix.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
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 TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ScannerFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("ScannerFix")]
[assembly: AssemblyCopyright("Copyright QERT2002© 2024")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace ScannerFix;

[HarmonyPatch]
internal class HudManagerPatcher
{
	public static TextMeshProUGUI totalCountTextComp;

	public static Image globalScanInfoImage;

	public static GameObject MyUICircleObject;

	public static TextMeshProUGUI MyUICircleObject_Text;

	public static bool SuccessTranspillerPatch;

	public static Vector3 scrapCenter;

	public static int AllActiveScrapOnDisplay;

	public static bool PrevImageState;

	public static MethodInfo m_MyExtraMethod = typeof(HudManagerPatcher).GetMethod("DisplayTotalCount", BindingFlags.Static | BindingFlags.Public);

	[HarmonyPostfix]
	[HarmonyPatch(typeof(HUDManager), "Awake")]
	public static void OV_HUDManager_Awake(HUDManager __instance)
	{
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Expected O, but got Unknown
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05de: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_065d: Unknown result type (might be due to invalid IL or missing references)
		//IL_067e: Unknown result type (might be due to invalid IL or missing references)
		//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_075b: Unknown result type (might be due to invalid IL or missing references)
		//IL_077c: Unknown result type (might be due to invalid IL or missing references)
		//IL_07da: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0859: Unknown result type (might be due to invalid IL or missing references)
		//IL_087a: Unknown result type (might be due to invalid IL or missing references)
		//IL_09dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_09e3: Expected O, but got Unknown
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Expected O, but got Unknown
		int value = SkannerFixConfig.MaxScrapToDisplay.Value;
		bool value2 = SkannerFixConfig.EnabledFpsBoostUI.Value;
		typeof(HUDManager).GetField("scanNodesHit", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(HUDManager.Instance, new RaycastHit[value]);
		GameObject val = GameObject.Find("Systems/UI/Canvas/ObjectScanner");
		GameObject val2 = GameObject.Find("Systems/UI/Canvas/ObjectScanner/ScanObject");
		int num = 13;
		int num2 = value - num;
		if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
		{
			GameObject val3 = GameObject.Find("Systems/UI/Canvas/ObjectScanner/GlobalScanInfo/AnimContainer/Image");
			GameObject val4 = GameObject.Find("Systems/UI/Canvas/ObjectScanner/GlobalScanInfo/AnimContainer/Image/TotalText");
			if ((Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null)
			{
				GameObject val5 = GameObject.Find("Systems/UI/Canvas/ObjectScanner/GlobalScanInfo/AnimContainer/Image/TotalNum");
				if ((Object)(object)val5 != (Object)null)
				{
					TextMeshProUGUI component = val5.GetComponent<TextMeshProUGUI>();
					((TMP_Text)component).enableAutoSizing = true;
					((TMP_Text)component).fontSizeMax = 21f;
				}
				globalScanInfoImage = val3.GetComponent<Image>();
				GameObject val6 = Object.Instantiate<GameObject>(val4);
				((Object)val6).name = "TotalCount_qert_ScannerFix";
				val6.transform.SetParent(val3.transform, false);
				Vector3 localPosition = val4.transform.localPosition;
				localPosition.y = -29f;
				val6.transform.localPosition = localPosition;
				totalCountTextComp = val6.GetComponent<TextMeshProUGUI>();
				val6.SetActive(true);
				((Behaviour)totalCountTextComp).enabled = false;
			}
			for (int i = 0; i < num2; i++)
			{
				GameObject val7 = Object.Instantiate<GameObject>(val2);
				((Object)val7).name = $"ScanObject ({num})";
				num++;
				val7.SetActive(false);
				val7.transform.SetParent(val.transform, false);
			}
			if (value2 && (Object)(object)MyUICircleObject == (Object)null)
			{
				MyUICircleObject = Object.Instantiate<GameObject>(val2);
				((Object)MyUICircleObject).name = "BigScanObject";
				MyUICircleObject.SetActive(false);
				scrapCenter = Vector3.zero;
				Object.Destroy((Object)(object)((Component)MyUICircleObject.transform.Find("Text/SubTextBox")).gameObject);
				Object.Destroy((Object)(object)((Component)MyUICircleObject.transform.Find("Text/SubText")).gameObject);
				foreach (Transform item in MyUICircleObject.transform)
				{
					Transform val8 = item;
					if (!(((Object)val8).name == "Text"))
					{
						continue;
					}
					foreach (Transform item2 in val8)
					{
						Transform val9 = item2;
						if (((Object)val9).name == "HeaderText")
						{
							val9.SetParent(val8.Find("HeaderTextBox"));
						}
					}
				}
				Transform val10 = MyUICircleObject.transform.Find("Text/HeaderTextBox");
				GameObject val11 = Object.Instantiate<GameObject>(((Component)val10).gameObject);
				Object.Destroy((Object)(object)val11.GetComponent<Image>());
				Object.Destroy((Object)(object)val11.GetComponent<Outline>());
				((Object)val11).name = "HeaderTextBox_Panel";
				Object.Destroy((Object)(object)((Component)val11.transform.GetChild(0)).gameObject);
				val11.transform.SetParent(MyUICircleObject.transform.Find("Text"));
				val10.SetParent(val11.transform);
				Transform val12 = MyUICircleObject.transform.Find("Text/HeaderTextBox_Panel/HeaderTextBox");
				val11.AddComponent<HorizontalLayoutGroup>();
				HorizontalLayoutGroup component2 = val11.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component2).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component2).childScaleHeight = false;
				((HorizontalOrVerticalLayoutGroup)component2).childScaleWidth = false;
				val11.AddComponent<ContentSizeFitter>();
				ContentSizeFitter component3 = val11.GetComponent<ContentSizeFitter>();
				component3.horizontalFit = (FitMode)0;
				component3.verticalFit = (FitMode)2;
				val11.AddComponent<LayoutElement>();
				LayoutElement component4 = val11.GetComponent<LayoutElement>();
				component4.preferredHeight = 240f;
				component4.flexibleHeight = 0f;
				component4.flexibleWidth = 0f;
				component4.layoutPriority = 1;
				RectTransform component5 = val11.GetComponent<RectTransform>();
				component5.sizeDelta = new Vector2(1000f, 640f);
				((Component)val12).gameObject.AddComponent<HorizontalLayoutGroup>();
				HorizontalLayoutGroup component6 = ((Component)val12).gameObject.GetComponent<HorizontalLayoutGroup>();
				((LayoutGroup)component6).padding.left = 5;
				((LayoutGroup)component6).padding.right = 5;
				((LayoutGroup)component6).padding.top = 5;
				((LayoutGroup)component6).padding.bottom = 5;
				((HorizontalOrVerticalLayoutGroup)component6).spacing = 20f;
				((HorizontalOrVerticalLayoutGroup)component6).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component6).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandWidth = false;
				((HorizontalOrVerticalLayoutGroup)component6).childScaleHeight = false;
				((HorizontalOrVerticalLayoutGroup)component6).childScaleWidth = false;
				MyUICircleObject.transform.SetParent(val.transform, false);
				Transform val13 = MyUICircleObject.transform.Find("Text/HeaderTextBox_Panel/HeaderTextBox/HeaderText");
				((TMP_Text)((Component)val13).GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)((Component)val13).GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				GameObject val14 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val14.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)val14.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val14.transform.SetParent(val12);
				val14.transform.localScale = new Vector3(1f, 1f, 1f);
				val14.transform.localPosition = new Vector3(0f, 0f, 0f);
				GameObject val15 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val15.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)val15.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val15.transform.SetParent(val12);
				val15.transform.localScale = new Vector3(1f, 1f, 1f);
				val15.transform.localPosition = new Vector3(0f, 0f, 0f);
				GameObject val16 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val16.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)val16.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val16.transform.SetParent(val12);
				val16.transform.localScale = new Vector3(1f, 1f, 1f);
				val16.transform.localPosition = new Vector3(0f, 0f, 0f);
				GameObject val17 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val17.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)val17.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val17.transform.SetParent(val12);
				val17.transform.localScale = new Vector3(1f, 1f, 1f);
				val17.transform.localPosition = new Vector3(0f, 0f, 0f);
				GameObject val18 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val18.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)6;
				((TMP_Text)val18.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val18.transform.SetParent(val12);
				val18.transform.localScale = new Vector3(1f, 1f, 1f);
				val18.transform.localPosition = new Vector3(0f, 0f, 0f);
				GameObject val19 = Object.Instantiate<GameObject>(((Component)val13).gameObject);
				((TMP_Text)val19.GetComponent<TextMeshProUGUI>()).overflowMode = (TextOverflowModes)1;
				((TMP_Text)val19.GetComponent<TextMeshProUGUI>()).fontSize = 10f;
				val19.transform.SetParent(val12);
				val19.transform.localScale = new Vector3(1f, 1f, 1f);
				val19.transform.localPosition = new Vector3(0f, 0f, 0f);
				((TMP_Text)((Component)val13).GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val14.GetComponent<TextMeshProUGUI>();
				((TMP_Text)val14.GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val15.GetComponent<TextMeshProUGUI>();
				((TMP_Text)val15.GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val16.GetComponent<TextMeshProUGUI>();
				((TMP_Text)val16.GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val17.GetComponent<TextMeshProUGUI>();
				((TMP_Text)val17.GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val18.GetComponent<TextMeshProUGUI>();
				((TMP_Text)val18.GetComponent<TextMeshProUGUI>()).linkedTextComponent = (TMP_Text)(object)val19.GetComponent<TextMeshProUGUI>();
				MyUICircleObject_Text = ((Component)MyUICircleObject.transform.Find("Text/HeaderTextBox_Panel/HeaderTextBox/HeaderText")).GetComponent<TextMeshProUGUI>();
			}
			HUDManager.Instance.scanElements = (RectTransform[])(object)new RectTransform[value];
			for (int j = 0; j < value; j++)
			{
				if (j == 0)
				{
					HUDManager.Instance.scanElements[j] = GameObject.Find("Systems/UI/Canvas/ObjectScanner/ScanObject").GetComponent<RectTransform>();
				}
				else
				{
					HUDManager.Instance.scanElements[j] = GameObject.Find($"Systems/UI/Canvas/ObjectScanner/ScanObject ({j})").GetComponent<RectTransform>();
				}
			}
			if (value2)
			{
				RectTransform[] scanElements = HUDManager.Instance.scanElements;
				foreach (RectTransform val20 in scanElements)
				{
					foreach (Transform item3 in ((Component)val20).gameObject.transform)
					{
						Transform val21 = item3;
						((Component)val21).gameObject.SetActive(false);
					}
				}
				AllActiveScrapOnDisplay = 0;
			}
		}
		Debug.Log((object)$"[QERT_SkannerFix] Now the scanner will show you a maximum of [{value}] units of scrap!");
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(HUDManager), "AssignNewNodes")]
	public static void OV_HUDManager_AssignNewNodes(HUDManager __instance)
	{
		if ((Object)(object)__instance != (Object)null && !SuccessTranspillerPatch)
		{
			object value = typeof(HUDManager).GetField("scannedScrapNum", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			if (value != null)
			{
				((TMP_Text)totalCountTextComp).text = $"Count:{(int)value}";
			}
		}
	}

	public static Vector3 calculateCentroid(Vector3[] arrayVectors)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(0f, 0f, 0f);
		int num = arrayVectors.Length;
		foreach (Vector3 val2 in arrayVectors)
		{
			val += val2;
		}
		val /= (float)num;
		return val;
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public static void AddScrapToDisplay(GameObject scrapUIObject, ScanNodeProperties value)
	{
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		AllActiveScrapOnDisplay++;
		List<ScanNodeProperties> list = (List<ScanNodeProperties>)typeof(HUDManager).GetField("nodesOnScreen", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(HUDManager.Instance);
		if (list.Count < SkannerFixConfig.ScrapAmountFor_FpsBoostStart.Value)
		{
			((Component)scrapUIObject.transform.GetChild(0)).gameObject.SetActive(true);
			((Component)scrapUIObject.transform.GetChild(1)).gameObject.SetActive(true);
		}
		else
		{
			if (!MyUICircleObject.activeSelf)
			{
				MyUICircleObject.SetActive(true);
				MyUICircleObject.GetComponent<Animator>().SetInteger("colorNumber", 2);
				List<Vector3> list2 = new List<Vector3>();
				foreach (ScanNodeProperties item in list)
				{
					if (item.nodeType == 2)
					{
						list2.Add(((Component)item).transform.position);
					}
				}
				scrapCenter = calculateCentroid(list2.ToArray());
			}
			if (value.nodeType == 2)
			{
				TextMeshProUGUI myUICircleObject_Text = MyUICircleObject_Text;
				((TMP_Text)myUICircleObject_Text).text = ((TMP_Text)myUICircleObject_Text).text + $"{value.headerText} -${value.scrapValue} \n";
			}
		}
		scrapUIObject.SetActive(true);
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public static void RemoveScrapFromDisplay(GameObject scrapUIObject)
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		if (AllActiveScrapOnDisplay != 0)
		{
			AllActiveScrapOnDisplay--;
		}
		scrapUIObject.SetActive(false);
		((Component)scrapUIObject.transform.GetChild(0)).gameObject.SetActive(false);
		((Component)scrapUIObject.transform.GetChild(1)).gameObject.SetActive(false);
		if (AllActiveScrapOnDisplay < SkannerFixConfig.ScrapAmountFor_FpsBoostStart.Value && MyUICircleObject.activeSelf)
		{
			MyUICircleObject.SetActive(false);
			scrapCenter = Vector3.zero;
			((TMP_Text)MyUICircleObject_Text).text = "";
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(HUDManager), "NodeIsNotVisible")]
	public static bool OV_NodeIsNotVisible(HUDManager __instance, ScanNodeProperties node, int elementIndex)
	{
		if (!SkannerFixConfig.EnabledFpsBoostUI.Value)
		{
			return true;
		}
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			List<ScanNodeProperties> list = (List<ScanNodeProperties>)typeof(HUDManager).GetField("nodesOnScreen", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(HUDManager.Instance);
			if (!list.Contains(node))
			{
				RemoveScrapFromDisplay(((Component)__instance.scanElements[elementIndex]).gameObject);
			}
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
	public static bool OV_UpdateScanNodes(HUDManager __instance, PlayerControllerB playerScript)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		if (!SkannerFixConfig.EnabledFpsBoostUI.Value)
		{
			return true;
		}
		Vector3 zero = Vector3.zero;
		if ((float)typeof(HUDManager).GetField("updateScanInterval", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance) <= 0f)
		{
			typeof(HUDManager).GetField("updateScanInterval", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, 0.25f);
			typeof(HUDManager).GetMethod("AssignNewNodes", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { playerScript });
		}
		float num = (float)typeof(HUDManager).GetField("updateScanInterval", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
		num -= Time.deltaTime;
		typeof(HUDManager).GetField("updateScanInterval", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, num);
		bool flag = false;
		for (int i = 0; i < __instance.scanElements.Length; i++)
		{
			Dictionary<RectTransform, ScanNodeProperties> dictionary = (Dictionary<RectTransform, ScanNodeProperties>)typeof(HUDManager).GetField("scanNodes", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			if (dictionary.Count > 0 && dictionary.TryGetValue(__instance.scanElements[i], out var value) && (Object)(object)value != (Object)null)
			{
				try
				{
					if ((bool)typeof(HUDManager).GetMethod("NodeIsNotVisible", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[2] { value, i }))
					{
						continue;
					}
					if (!((Component)__instance.scanElements[i]).gameObject.activeSelf)
					{
						AddScrapToDisplay(((Component)__instance.scanElements[i]).gameObject, value);
						((Component)__instance.scanElements[i]).GetComponent<Animator>().SetInteger("colorNumber", value.nodeType);
						if (value.creatureScanID != -1)
						{
							typeof(HUDManager).GetMethod("AttemptScanNewCreature", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[1] { value.creatureScanID });
						}
					}
					goto IL_02b0;
				}
				catch (Exception arg)
				{
					Debug.LogError((object)$"Error in updatescanNodes A: {arg}");
					goto IL_02b0;
				}
			}
			if (((Component)__instance.scanElements[i]).gameObject.activeSelf)
			{
				RemoveScrapFromDisplay(((Component)__instance.scanElements[i]).gameObject);
			}
			dictionary.Remove(__instance.scanElements[i]);
			typeof(HUDManager).GetField("scanNodes", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, dictionary);
			continue;
			IL_02b0:
			try
			{
				typeof(HUDManager).GetField("scanElementText", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, ((Component)__instance.scanElements[i]).gameObject.GetComponentsInChildren<TextMeshProUGUI>());
				TextMeshProUGUI[] array = (TextMeshProUGUI[])typeof(HUDManager).GetField("scanElementText", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
				if (array.Length > 1)
				{
					((TMP_Text)array[0]).text = value.headerText;
					((TMP_Text)array[1]).text = value.subText;
					typeof(HUDManager).GetField("scanElementText", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, array);
				}
				if (value.nodeType == 2)
				{
					flag = true;
				}
				if (scrapCenter != Vector3.zero)
				{
					Vector3 val = playerScript.gameplayCamera.WorldToScreenPoint(scrapCenter);
					MyUICircleObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(val.x - 439.48f, val.y - 244.8f);
				}
				zero = playerScript.gameplayCamera.WorldToScreenPoint(((Component)value).transform.position);
				__instance.scanElements[i].anchoredPosition = new Vector2(zero.x - 439.48f, zero.y - 244.8f);
			}
			catch (Exception arg2)
			{
				Debug.LogError((object)$"Error in updatescannodes B: {arg2}");
			}
		}
		try
		{
			if (!flag)
			{
				__instance.totalScrapScanned = 0;
				typeof(HUDManager).GetField("totalScrapScannedDisplayNum", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, 0);
				typeof(HUDManager).GetField("addToDisplayTotalInterval", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(__instance, 0.35f);
			}
			int num2 = (int)typeof(HUDManager).GetField("scannedScrapNum", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
			__instance.scanInfoAnimator.SetBool("display", num2 >= 2 && flag);
		}
		catch (Exception arg3)
		{
			Debug.LogError((object)$"Error in updatescannodes C: {arg3}");
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(HUDManager), "DisableAllScanElements")]
	public static bool OV_DisableAllScanElements(HUDManager __instance)
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		if (!SkannerFixConfig.EnabledFpsBoostUI.Value)
		{
			return true;
		}
		if ((Object)(object)__instance != (Object)null)
		{
			for (int i = 0; i < __instance.scanElements.Length; i++)
			{
				RemoveScrapFromDisplay(((Component)__instance.scanElements[i]).gameObject);
			}
			if ((Object)(object)MyUICircleObject != (Object)null)
			{
				MyUICircleObject.SetActive(false);
				scrapCenter = Vector3.zero;
				((TMP_Text)MyUICircleObject_Text).text = "";
			}
		}
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(HUDManager), "Update")]
	public static void OV_HUDManager_Update(HUDManager __instance)
	{
		if (!((Object)(object)__instance != (Object)null) || !((Object)(object)globalScanInfoImage != (Object)null))
		{
			return;
		}
		if (((Behaviour)globalScanInfoImage).enabled)
		{
			if (PrevImageState != ((Behaviour)globalScanInfoImage).enabled)
			{
				SetTotalCountTextEnabled(enabled: true);
				PrevImageState = ((Behaviour)globalScanInfoImage).enabled;
			}
		}
		else if (PrevImageState != ((Behaviour)globalScanInfoImage).enabled)
		{
			SetTotalCountTextEnabled(enabled: false);
			PrevImageState = ((Behaviour)globalScanInfoImage).enabled;
		}
	}

	public static void SetTotalCountTextEnabled(bool enabled)
	{
		((Behaviour)totalCountTextComp).enabled = enabled;
	}

	public static void DisplayTotalCount()
	{
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			object value = typeof(HUDManager).GetField("scannedScrapNum", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(HUDManager.Instance);
			if (value != null)
			{
				((TMP_Text)totalCountTextComp).text = $"Count:{(int)value}";
			}
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(HUDManager), "Update")]
	public static IEnumerable<CodeInstruction> OV_HUDManager_Update_Transpiller(IEnumerable<CodeInstruction> instructions)
	{
		bool found = false;
		foreach (CodeInstruction instruction in instructions)
		{
			if (((object)instruction).ToString() == "ldfld UnityEngine.AudioClip HUDManager::addToScrapTotalSFX")
			{
				yield return new CodeInstruction(OpCodes.Call, (object)m_MyExtraMethod);
				found = true;
			}
			if (((object)instruction).ToString() == "ldc.r4 10000")
			{
				yield return new CodeInstruction(OpCodes.Ldc_R4, (object)100000f);
			}
			else
			{
				yield return instruction;
			}
		}
		if (object.Equals(false, found))
		{
			Debug.Log((object)"[QERT_ScannerFix]Error: cannot find il instructions to patch HUDManager:Update, want to insert method after scrap scanned(UIAudio.PlayOneShot(addToScrapTotalSFX);)");
			SuccessTranspillerPatch = false;
		}
		else
		{
			SuccessTranspillerPatch = true;
		}
	}
}
public static class BoundsExtension
{
	public static Bounds GrowBounds(this Bounds a, Bounds b)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.Max(((Bounds)(ref a)).max, ((Bounds)(ref b)).max);
		Vector3 val2 = Vector3.Min(((Bounds)(ref a)).min, ((Bounds)(ref b)).min);
		((Bounds)(ref a))..ctor((val + val2) * 0.5f, val - val2);
		return a;
	}
}
[BepInPlugin("com.github.qert2002.ScannerFix", "ScannerFix", "1.2")]
internal class ScannerFix : BaseUnityPlugin
{
	public const string GUID = "com.github.qert2002.ScannerFix";

	public const string NAME = "ScannerFix";

	public const string VERSION = "1.2";

	internal static SkannerFixConfig Config;

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Config = new SkannerFixConfig(((BaseUnityPlugin)this).Config);
		Config.RegisterOptions();
		new Harmony("com.github.qert2002.ScannerFix").PatchAll(Assembly.GetExecutingAssembly());
	}

	private void Start()
	{
		SetLobbyCompatibility();
	}

	private void SetLobbyCompatibility()
	{
		if (!Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
		{
			return;
		}
		MethodInfo methodInfo = AccessTools.Method("LobbyCompatibility.Features.PluginHelper:RegisterPlugin", (Type[])null, (Type[])null);
		if ((object)methodInfo == null)
		{
			Log.LogWarning((object)"Found LobbyCompatibility mod but failed to find plugin register API method!");
			return;
		}
		Log.LogDebug((object)"Registering compatibility with LobbyCompatibility.");
		try
		{
			methodInfo.Invoke(null, new object[4]
			{
				"com.github.qert2002.ScannerFix",
				new Version("1.2"),
				0,
				0
			});
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Failed to register plugin compatibility with LobbyCompatibility.\n{arg}");
			return;
		}
		Log.LogDebug((object)"Successfully registered with LobbyCompatibility.");
	}
}
internal class SkannerFixConfig
{
	private readonly ConfigFile _configFile;

	public static ConfigEntry<int> MaxScrapToDisplay;

	public static ConfigEntry<bool> EnabledFpsBoostUI;

	public static ConfigEntry<int> ScrapAmountFor_FpsBoostStart;

	public SkannerFixConfig(ConfigFile configFile)
	{
		_configFile = configFile;
	}

	public void RegisterOptions()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		MaxScrapToDisplay = _configFile.Bind<int>("General", "MaxScrapToDisplay", 255, new ConfigDescription("How much scrap will the scanner show?(Min 13 - Max 255)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(13, 255), Array.Empty<object>()));
		EnabledFpsBoostUI = _configFile.Bind<bool>("General", "EnabledFpsBoostUI", true, new ConfigDescription("If enabled change many circles to one big(Boost your FPS)", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
		ScrapAmountFor_FpsBoostStart = _configFile.Bind<int>("General", "ScrapAmountFor_FpsBoostStart", 45, new ConfigDescription("How much scrap will need to activate FPS Boost (REQUIRE EnabledFpsBoostUI True)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(14, 255), Array.Empty<object>()));
	}
}