Decompiled source of PlanetFinder v1.1.5

PlanetFinder.dll

Decompiled 4 months ago
using System;
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 System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PlanetFinder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlanetFinder")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("43cacced-1c08-475c-80c9-8a77158a4bd9")]
[assembly: AssemblyFileVersion("1.1.5.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.5.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]
	internal sealed class IsReadOnlyAttribute : Attribute
	{
	}
	[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 PlanetFinder
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PlanetFinder";

		public const string PLUGIN_NAME = "PlanetFinder";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PlanetFinderMod
{
	public class CruiseAssistIntg
	{
		public MethodInfo _selectPlanetOrStar;

		public readonly bool canSelectPlanet;

		public CruiseAssistIntg()
		{
			canSelectPlanet = false;
			_selectPlanetOrStar = null;
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("tanu.CruiseAssist", out var value) && (Object)(object)value.Instance != (Object)null)
				{
					Type type = ((object)value.Instance).GetType().Assembly.GetType("tanu.CruiseAssist.CruiseAssistStarListUI");
					_selectPlanetOrStar = type.GetMethod("SelectStar", new Type[2]
					{
						typeof(StarData),
						typeof(PlanetData)
					});
					canSelectPlanet = _selectPlanetOrStar != null;
				}
			}
			catch (Exception)
			{
			}
		}

		public void SelectPlanetOrStar(PlanetData planet, StarData star = null)
		{
			if (!(_selectPlanetOrStar == null))
			{
				if (planet != null && star == null)
				{
					star = planet.star;
				}
				if (_selectPlanetOrStar != null && (planet != null || star != null))
				{
					object[] parameters = new object[2] { star, planet };
					_selectPlanetOrStar.Invoke(null, parameters);
				}
			}
		}
	}
	public class DSPStarMapMemoIntg
	{
		public readonly bool canGetSignalIconId;

		public readonly bool canGetDesc;

		private FieldInfo _memoPool;

		private FieldInfo _signalIconIdField;

		private FieldInfo _descField;

		public DSPStarMapMemoIntg()
		{
			canGetSignalIconId = false;
			canGetDesc = false;
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("Appun.DSP.plugin.StarMapMemo", out var value) && (Object)(object)value.Instance != (Object)null)
				{
					Type type = ((object)value.Instance).GetType().Assembly.GetType("DSPStarMapMemo.MemoPool");
					Type type2 = ((object)value.Instance).GetType().Assembly.GetType("DSPStarMapMemo.MemoPool+Memo");
					if (type != null && type2 != null)
					{
						_signalIconIdField = type2.GetField("signalIconId");
						_descField = type2.GetField("desc");
						_memoPool = type.GetField("memoPool", BindingFlags.Static | BindingFlags.Public);
					}
					canGetSignalIconId = _memoPool != null && _signalIconIdField != null;
					canGetDesc = _memoPool != null && _descField != null;
				}
			}
			catch (Exception)
			{
			}
		}

		public int GetSignalIconId(int planetId)
		{
			if (_memoPool != null && _signalIconIdField != null)
			{
				object value = _memoPool.GetValue(null);
				if (value == null)
				{
					return 0;
				}
				object[] array = new object[2] { planetId, null };
				if ((bool)value.GetType().InvokeMember("TryGetValue", BindingFlags.InvokeMethod, null, value, array) && array.Length == 2 && array[1] != null)
				{
					object value2 = _signalIconIdField.GetValue(array[1]);
					if (value2 != null)
					{
						int[] array2 = value2 as int[];
						for (int i = 0; i < array2.Length; i++)
						{
							if (array2[i] != 0)
							{
								return array2[i];
							}
						}
					}
				}
			}
			return 0;
		}

		public string GetDesc(int planetId)
		{
			if (_memoPool != null && _descField != null)
			{
				object value = _memoPool.GetValue(null);
				if (value == null)
				{
					return null;
				}
				object[] array = new object[2] { planetId, null };
				if ((bool)value.GetType().InvokeMember("TryGetValue", BindingFlags.InvokeMethod, null, value, array) && array.Length == 2 && array[1] != null)
				{
					object value2 = _descField.GetValue(array[1]);
					if (value2 != null)
					{
						return value2 as string;
					}
				}
			}
			return null;
		}
	}
	public class LSTMIntg
	{
		public MethodInfo _openPlanetId;

		public readonly bool canOpenPlanetId;

		public LSTMIntg()
		{
			canOpenPlanetId = false;
			_openPlanetId = null;
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("com.hetima.dsp.LSTM", out var value) && (Object)(object)value.Instance != (Object)null)
				{
					_openPlanetId = ((object)value.Instance).GetType().GetMethod("IntegrationOpenPlanetId", new Type[1] { typeof(int) });
					canOpenPlanetId = _openPlanetId != null;
				}
			}
			catch (Exception)
			{
			}
		}

		public void OpenPlanetId(int planetId)
		{
			if (_openPlanetId != null)
			{
				object[] parameters = new object[1] { planetId };
				_openPlanetId.Invoke(null, parameters);
			}
		}
	}
	public class MyCheckBox : MonoBehaviour
	{
		public UIButton uiButton;

		public Image checkImage;

		public RectTransform rectTrans;

		public Text labelText;

		public ConfigEntry<bool> config;

		public static RectTransform CreateCheckBox(ConfigEntry<bool> config, string label = "", int fontSize = 17)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)UIRoot.instance.uiGame.buildMenu.uxFacilityCheck).gameObject);
			((Object)val).name = "my-checkbox";
			MyCheckBox cb = val.AddComponent<MyCheckBox>();
			cb.config = config;
			Transform transform = val.transform;
			RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			cb.rectTrans = val2;
			ResetAnchor(val2);
			val2.anchoredPosition3D = new Vector3(0f, 0f, 0f);
			cb.uiButton = val.GetComponent<UIButton>();
			MyCheckBox myCheckBox = cb;
			Transform obj = val.transform.Find("checked");
			myCheckBox.checkImage = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			Transform val3 = val.transform.Find("text");
			if ((Object)(object)val3 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val3).GetComponent<Localizer>());
				cb.labelText = ((Component)val3).GetComponent<Text>();
				cb.labelText.fontSize = fontSize;
				cb.SetLabelText(label);
			}
			cb.uiButton.onClick += cb.OnClick;
			cb.SettingChanged();
			config.SettingChanged += delegate
			{
				cb.SettingChanged();
			};
			return cb.rectTrans;
			static void ResetAnchor(RectTransform rect_)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				rect_.anchorMax = Vector2.zero;
				rect_.anchorMin = Vector2.zero;
			}
		}

		public void SetLabelText(string val)
		{
			if ((Object)(object)labelText != (Object)null)
			{
				labelText.text = val;
			}
		}

		public void SettingChanged()
		{
			if (config.Value != ((Behaviour)checkImage).enabled)
			{
				((Behaviour)checkImage).enabled = config.Value;
			}
		}

		public void OnClick(int obj)
		{
			config.Value = !config.Value;
		}
	}
	public class MyKeyBinder : MonoBehaviour
	{
		public ConfigEntry<KeyboardShortcut> config;

		[SerializeField]
		public Text functionText;

		[SerializeField]
		public Text keyText;

		[SerializeField]
		public InputField setTheKeyInput;

		[SerializeField]
		public Toggle setTheKeyToggle;

		[SerializeField]
		public RectTransform rectTrans;

		[SerializeField]
		public UIButton inputUIButton;

		[SerializeField]
		public Text conflictText;

		[SerializeField]
		public Text waitingText;

		[SerializeField]
		public UIButton setDefaultUIButton;

		[SerializeField]
		public UIButton setNoneKeyUIButton;

		private bool nextNotOn;

		private KeyCode _lastKey;

		private static KeyCode[] modKeys;

		public static RectTransform CreateKeyBinder(ConfigEntry<KeyboardShortcut> config, string label = "")
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			UIKeyEntry val = Object.Instantiate<UIKeyEntry>(UIRoot.instance.optionWindow.entryPrefab);
			((Component)val).gameObject.SetActive(true);
			GameObject gameObject = ((Component)val).gameObject;
			((Object)gameObject).name = "my-keybinder";
			MyKeyBinder kb = gameObject.AddComponent<MyKeyBinder>();
			kb.config = config;
			kb.functionText = val.functionText;
			kb.keyText = val.keyText;
			kb.setTheKeyInput = val.setTheKeyInput;
			kb.setTheKeyToggle = val.setTheKeyToggle;
			kb.rectTrans = val.rectTrans;
			kb.inputUIButton = val.inputUIButton;
			kb.conflictText = val.conflictText;
			kb.waitingText = val.waitingText;
			kb.setDefaultUIButton = val.setDefaultUIButton;
			kb.setNoneKeyUIButton = val.setNoneKeyUIButton;
			kb.functionText.text = label;
			kb.functionText.fontSize = 17;
			Transform transform = ((Component)kb.keyText).transform;
			((RectTransform)((transform is RectTransform) ? transform : null)).anchoredPosition = new Vector2(20f, -22f);
			kb.keyText.fontSize = 17;
			Transform transform2 = ((Component)((Component)kb.inputUIButton).transform.parent).transform;
			((RectTransform)((transform2 is RectTransform) ? transform2 : null)).anchoredPosition = new Vector2(20f, -52f);
			Transform transform3 = ((Component)kb.setDefaultUIButton).transform;
			((RectTransform)((transform3 is RectTransform) ? transform3 : null)).anchoredPosition = new Vector2(160f, -52f);
			Transform transform4 = ((Component)kb.setNoneKeyUIButton).transform;
			((RectTransform)((transform4 is RectTransform) ? transform4 : null)).anchoredPosition = new Vector2(260f, -52f);
			Transform transform5 = gameObject.transform;
			Transform obj = ((transform5 is RectTransform) ? transform5 : null);
			ResetAnchor((RectTransform)(object)obj);
			Object.Destroy((Object)(object)val);
			((Component)kb.setNoneKeyUIButton).gameObject.SetActive(false);
			kb.SettingChanged();
			config.SettingChanged += delegate
			{
				kb.SettingChanged();
			};
			kb.inputUIButton.onClick += kb.OnInputUIButtonClick;
			kb.setDefaultUIButton.onClick += kb.OnSetDefaultKeyClick;
			return (RectTransform)(object)obj;
			static void ResetAnchor(RectTransform rect_)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				rect_.anchorMax = Vector2.zero;
				rect_.anchorMin = Vector2.zero;
			}
		}

		private void Update()
		{
			if (!setTheKeyToggle.isOn && inputUIButton.highlighted)
			{
				setTheKeyToggle.isOn = true;
			}
			if (!setTheKeyToggle.isOn)
			{
				return;
			}
			if (!inputUIButton._isPointerEnter && Input.GetKeyDown((KeyCode)323))
			{
				inputUIButton.highlighted = false;
				setTheKeyToggle.isOn = false;
				Reset();
				return;
			}
			if (!inputUIButton.highlighted)
			{
				setTheKeyToggle.isOn = false;
				Reset();
				return;
			}
			((Component)waitingText).gameObject.SetActive(true);
			if (TrySetValue())
			{
				setTheKeyToggle.isOn = false;
				inputUIButton.highlighted = false;
				Reset();
			}
		}

		public bool TrySetValue()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKey((KeyCode)27))
			{
				VFInput.UseEscape();
				return true;
			}
			if (Input.GetKey((KeyCode)323) || Input.GetKey((KeyCode)324))
			{
				return true;
			}
			if (!GetIunptKeys() && (int)_lastKey != 0)
			{
				string pressedKey = GetPressedKey();
				if (string.IsNullOrEmpty(pressedKey))
				{
					return false;
				}
				_lastKey = (KeyCode)0;
				config.Value = KeyboardShortcut.Deserialize(pressedKey);
				return true;
			}
			return false;
		}

		public string GetPressedKey()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			string text = ((object)(KeyCode)(ref _lastKey)).ToString();
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			string text2 = "";
			KeyCode[] array = modKeys;
			for (int i = 0; i < array.Length; i++)
			{
				KeyCode val = array[i];
				if (Input.GetKey(val))
				{
					text2 = text2 + "+" + ((object)(KeyCode)(ref val)).ToString();
				}
			}
			if (!string.IsNullOrEmpty(text2))
			{
				text += text2;
			}
			return text;
		}

		public bool GetIunptKeys()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0033: 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_0044: 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)
			bool result = false;
			new List<KeyCode>();
			foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
			{
				if ((int)value != 0 && !modKeys.Contains(value) && Input.GetKey(value))
				{
					_lastKey = value;
					result = true;
				}
			}
			return result;
		}

		public void Reset()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			((Component)conflictText).gameObject.SetActive(false);
			((Component)waitingText).gameObject.SetActive(false);
			((Selectable)setDefaultUIButton.button).Select();
			_lastKey = (KeyCode)0;
		}

		public void OnInputUIButtonClick(int data)
		{
			inputUIButton.highlighted = true;
			if (nextNotOn)
			{
				nextNotOn = false;
				inputUIButton.highlighted = false;
				setTheKeyToggle.isOn = false;
				((Component)waitingText).gameObject.SetActive(false);
			}
		}

		public void OnSetDefaultKeyClick(int data)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			config.Value = (KeyboardShortcut)((ConfigEntryBase)config).DefaultValue;
			Text obj = keyText;
			KeyboardShortcut value = config.Value;
			obj.text = ((KeyboardShortcut)(ref value)).Serialize();
		}

		public void OnSetNoneKeyClick(int data)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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)
			config.Value = (KeyboardShortcut)((ConfigEntryBase)config).DefaultValue;
			Text obj = keyText;
			KeyboardShortcut value = config.Value;
			obj.text = ((KeyboardShortcut)(ref value)).Serialize();
		}

		public void SettingChanged()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Text obj = keyText;
			KeyboardShortcut value = config.Value;
			obj.text = ((KeyboardShortcut)(ref value)).Serialize();
		}

		static MyKeyBinder()
		{
			KeyCode[] array = new KeyCode[12];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			modKeys = (KeyCode[])(object)array;
		}
	}
	public class MyListView : MonoBehaviour
	{
		public RecyclingListView recyclingListView;

		public ScrollRect m_ScrollRect;

		public static MyListView CreateListView(MonoBehaviour preFab, RecyclingListView.ItemDelegate dlgt, string goName = "", Transform parent = null, float vsWidth = 16f)
		{
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)UIRoot.instance.uiGame.tutorialWindow.entryList).gameObject);
			if ((Object)(object)parent != (Object)null)
			{
				val.transform.SetParent(parent, false);
			}
			if (!string.IsNullOrEmpty(goName))
			{
				((Object)val).name = goName;
			}
			UIListView component = val.GetComponent<UIListView>();
			GameObject gameObject = ((Component)component.m_ContentPanel).gameObject;
			MyListView myListView = val.AddComponent<MyListView>();
			myListView.recyclingListView = gameObject.AddComponent<RecyclingListView>();
			Object.Destroy((Object)(object)gameObject.transform.GetChild(0));
			gameObject.transform.DetachChildren();
			myListView.recyclingListView.ChildPrefab = preFab;
			myListView.recyclingListView.ItemCallback = dlgt;
			myListView.m_ScrollRect = component.m_ScrollRect;
			myListView.recyclingListView.scrollRect = myListView.m_ScrollRect;
			((Component)myListView.recyclingListView.scrollRect.horizontalScrollbar).gameObject.SetActive(false);
			((Component)myListView.recyclingListView.scrollRect.verticalScrollbar).gameObject.SetActive(true);
			myListView.recyclingListView.scrollRect.vertical = true;
			myListView.recyclingListView.scrollRect.horizontal = false;
			myListView.recyclingListView.RowPadding = 4f;
			Image component2 = ((Component)myListView.recyclingListView.scrollRect.verticalScrollbar).GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Graphic)component2).color = new Color(0f, 0f, 0f, 0.62f);
			}
			Transform transform = ((Component)myListView.recyclingListView.scrollRect.verticalScrollbar).transform;
			RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			val2.sizeDelta = new Vector2(vsWidth, val2.sizeDelta.y);
			Object.Destroy((Object)(object)component.m_ContentPanel);
			Object.Destroy((Object)(object)component);
			return myListView;
		}

		public void Clear()
		{
			recyclingListView.Clear();
		}

		public void SetItemCount(int num)
		{
			recyclingListView.RowCount = num;
		}
	}
	public class MySlider : MonoBehaviour
	{
		public Slider slider;

		public RectTransform rectTrans;

		public Text labelText;

		public string labelFormat;

		public ConfigEntry<float> config;

		private bool _sliderEventLock;

		public static RectTransform CreateSlider(ConfigEntry<float> config, float minValue, float maxValue, string format = "0", float width = 0f)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)UIRoot.instance.optionWindow.audioVolumeComp).gameObject);
			((Object)val).name = "my-slider";
			val.SetActive(true);
			MySlider sl = val.AddComponent<MySlider>();
			sl.config = config;
			Transform transform = val.transform;
			RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			sl.rectTrans = val2;
			ResetAnchor(val2);
			if (width > 0f)
			{
				val2.sizeDelta = new Vector2(width, val2.sizeDelta.y);
			}
			sl.slider = val.GetComponent<Slider>();
			sl.slider.minValue = minValue;
			sl.slider.maxValue = maxValue;
			((UnityEventBase)sl.slider.onValueChanged).RemoveAllListeners();
			((UnityEvent<float>)(object)sl.slider.onValueChanged).AddListener((UnityAction<float>)sl.SliderChanged);
			MySlider mySlider = sl;
			Slider obj = sl.slider;
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				RectTransform handleRect = obj.handleRect;
				if (handleRect == null)
				{
					obj2 = null;
				}
				else
				{
					Transform obj3 = ((Transform)handleRect).Find("Text");
					obj2 = ((obj3 != null) ? ((Component)obj3).GetComponent<Text>() : null);
				}
			}
			mySlider.labelText = (Text)obj2;
			if ((Object)(object)sl.labelText != (Object)null)
			{
				sl.labelText.fontSize = 14;
				Transform transform2 = ((Component)sl.labelText).transform;
				((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta = new Vector2(22f, 22f);
			}
			sl.labelFormat = format;
			Transform obj4 = ((Component)sl.slider).transform.Find("Background");
			Image val3 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null);
			if ((Object)(object)val3 != (Object)null)
			{
				((Graphic)val3).color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
			}
			Image component = ((Component)sl.slider.fillRect).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				((Graphic)component).color = new Color(1f, 1f, 1f, 0.28f);
			}
			sl.SettingChanged();
			sl.UpdateLabel();
			config.SettingChanged += delegate
			{
				sl.SettingChanged();
			};
			return sl.rectTrans;
			static void ResetAnchor(RectTransform rect_)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: 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)
				rect_.anchorMax = Vector2.zero;
				rect_.anchorMin = Vector2.zero;
				rect_.anchoredPosition3D = new Vector3(0f, 0f, 0f);
			}
		}

		public void SettingChanged()
		{
			if (_sliderEventLock)
			{
				return;
			}
			_sliderEventLock = true;
			if (config.Value != slider.value)
			{
				float num = config.Value;
				if (num > slider.maxValue)
				{
					num = slider.maxValue;
				}
				else if (num < slider.minValue)
				{
					num = slider.minValue;
				}
				slider.value = num;
				UpdateLabel();
			}
			_sliderEventLock = false;
		}

		public void UpdateLabel()
		{
			if ((Object)(object)labelText != (Object)null)
			{
				labelText.text = config.Value.ToString(labelFormat);
			}
		}

		public void SliderChanged(float val)
		{
			if (!_sliderEventLock)
			{
				_sliderEventLock = true;
				float value = Mathf.Round(slider.value);
				config.Value = value;
				UpdateLabel();
				_sliderEventLock = false;
			}
		}
	}
	public interface MyWindow
	{
		void TryClose();

		bool isFunctionWindow();
	}
	public static class MyWindowCtl
	{
		public static class Patch
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "_OnCreate")]
			public static void UIGame__OnCreate_Postfix()
			{
				_created = true;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "_OnDestroy")]
			public static void UIGame__OnDestroy_Postfix()
			{
				foreach (ManualBehaviour window in _windows)
				{
					window._Destroy();
				}
				_windows.Clear();
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "_OnInit")]
			public static void UIGame__OnInit_Postfix(UIGame __instance)
			{
				foreach (ManualBehaviour window in _windows)
				{
					window._Init(window.data);
				}
				_inited = true;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "_OnFree")]
			public static void UIGame__OnFree_Postfix()
			{
				foreach (ManualBehaviour window in _windows)
				{
					window._Free();
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "_OnUpdate")]
			public static void UIGame__OnUpdate_Postfix()
			{
				if (GameMain.isPaused || !GameMain.isRunning)
				{
					return;
				}
				foreach (ManualBehaviour window in _windows)
				{
					window._Update();
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIGame), "ShutAllFunctionWindow")]
			public static void UIGame_ShutAllFunctionWindow_Postfix()
			{
				foreach (ManualBehaviour window in _windows)
				{
					if (useMyWindowInterface)
					{
						if ((window as MyWindow).isFunctionWindow())
						{
							(window as MyWindow).TryClose();
						}
					}
					else
					{
						window._Close();
					}
				}
			}
		}

		public static bool useMyWindowInterface = true;

		public static List<ManualBehaviour> _windows = new List<ManualBehaviour>(4);

		internal static bool _created = false;

		internal static bool _inited = false;

		public static T CreateWindow<T>(string name, string title = "") where T : Component
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			UITankWindow tankWindow = UIRoot.instance.uiGame.tankWindow;
			GameObject val = Object.Instantiate<GameObject>(((Component)tankWindow).gameObject, ((Component)tankWindow).transform.parent);
			((Object)val).name = name;
			val.SetActive(false);
			Object.Destroy((Object)(object)val.GetComponent<UITankWindow>());
			object obj = val.AddComponent<T>();
			ManualBehaviour val2 = (ManualBehaviour)((obj is ManualBehaviour) ? obj : null);
			for (int i = 0; i < val.transform.childCount; i++)
			{
				GameObject gameObject = ((Component)val.transform.GetChild(i)).gameObject;
				if (((Object)gameObject).name == "panel-bg")
				{
					Button componentInChildren = gameObject.GetComponentInChildren<Button>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						((UnityEvent)componentInChildren.onClick).AddListener(new UnityAction(val2._Close));
					}
				}
				else if (((Object)gameObject).name != "shadow" && ((Object)gameObject).name != "panel-bg")
				{
					Object.Destroy((Object)(object)gameObject);
				}
			}
			SetTitle(val2, title);
			val2._Create();
			if (_inited)
			{
				val2._Init(val2.data);
			}
			_windows.Add(val2);
			return (T)(object)((val2 is T) ? val2 : null);
		}

		public static void SetTitle(ManualBehaviour win, string title)
		{
			Text titleText = GetTitleText(win);
			if (Object.op_Implicit((Object)(object)titleText))
			{
				titleText.text = title;
			}
		}

		public static Text GetTitleText(ManualBehaviour win)
		{
			Transform obj = ((Component)win).gameObject.transform.Find("panel-bg/title-text");
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).gameObject.GetComponent<Text>();
		}

		public static RectTransform GetRectTransform(ManualBehaviour win)
		{
			return ((Component)win).GetComponent<RectTransform>();
		}

		public static void SetRect(ManualBehaviour win, RectTransform rect)
		{
			((Component)win).GetComponent<RectTransform>();
		}

		public static void OpenWindow(ManualBehaviour win)
		{
			win._Open();
			((Component)win).transform.SetAsLastSibling();
		}

		public static void CloseWindow(ManualBehaviour win)
		{
			win._Close();
		}
	}
	[BepInPlugin("com.hetima.dsp.PlanetFinder", "PlanetFinder", "1.1.5")]
	public class PLFN : BaseUnityPlugin
	{
		private static class Patch
		{
			internal static bool _initialized;

			[HarmonyPrefix]
			[HarmonyPatch(typeof(GameMain), "Begin")]
			public static void GameMain_Begin_Prefix()
			{
				if (!_initialized)
				{
					_initialized = true;
					aLSTMIntg = new LSTMIntg();
					aDSPStarMapMemoIntg = new DSPStarMapMemoIntg();
					aCruiseAssistIntg = new CruiseAssistIntg();
					planetFinder = UIPlanetFinderWindow.CreateInstance();
					_configWin = UIConfigWindow.CreateWindow();
					recentPlanets = new List<PlanetData>(100);
					CreateUI();
				}
				planetFinder?.BeginGame();
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(DSPGame), "EndGame")]
			public static void DSPGame_EndGame_Prefix()
			{
				planetFinder?.EndGame();
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(GameData), "ArrivePlanet")]
			public static void GameData_ArrivePlanet(PlanetData planet)
			{
				AddRecentPlanet(planet);
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(UIPlanetDetail), "RefreshDynamicProperties")]
			public static void UIPlanetDetail_RefreshDynamicProperties(UIPlanetDetail __instance)
			{
				if (showFavButtonInStarmap.Value && favBtnGO.activeSelf)
				{
					favBtnGO.GetComponent<UIButton>().highlighted = IsFavPlanet(__instance.planet);
				}
			}
		}

		public const string __NAME__ = "PlanetFinder";

		public const string __GUID__ = "com.hetima.dsp.PlanetFinder";

		internal static ManualLogSource Logger;

		public static UIPlanetFinderWindow planetFinder;

		public static UIConfigWindow _configWin;

		public static List<PlanetData> recentPlanets;

		public static ConfigEntry<KeyboardShortcut> mainWindowHotkey;

		public static ConfigEntry<bool> showButtonInMainPanel;

		public static ConfigEntry<bool> showButtonInStarmap;

		public static ConfigEntry<bool> showFavButtonInStarmap;

		public static ConfigEntry<bool> showPowerState;

		public static ConfigEntry<bool> showPrefix;

		public static ConfigEntry<string> gasGiantPrefix;

		public static ConfigEntry<string> tidalLockedPrefix;

		public static ConfigEntry<float> mainWindowSize;

		public static ConfigEntry<bool> integrationWithDSPStarMapMemo;

		public static ConfigEntry<bool> integrationWithLSTM;

		public static ConfigEntry<bool> integrationWithCruiseAssist;

		public static GameObject panelButtonGO;

		public static GameObject starmapButtonGO;

		public static GameObject favBtnGO;

		public static LSTMIntg aLSTMIntg;

		public static DSPStarMapMemoIntg aDSPStarMapMemoIntg;

		public static CruiseAssistIntg aCruiseAssistIntg;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("com.hetima.dsp.PlanetFinder");
			mainWindowHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keyboard Shortcuts", "mainWindowHotkey", KeyboardShortcut.Deserialize("F + LeftControl"), "Hotkey to open/close window");
			showButtonInMainPanel = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "showButtonInMainPanel", true, "show open/close button in main panel");
			showButtonInStarmap = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "showButtonInStarmap", true, "show open/close button in starmap");
			showFavButtonInStarmap = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "showFavButtonInStarmap", false, "show toggle favorited button in starmap planet detail panel");
			showPowerState = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "showPowerState", true, "show power consumption");
			showPrefix = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "showPrefix", true, "show prefix [GAS] and [TL]");
			gasGiantPrefix = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "gasGiantPrefix", "[GAS]", "gas giant prefix default is [GAS]");
			tidalLockedPrefix = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "tidalLockedPrefix", "[TL]", "tidal locked prefix default is [TL]");
			mainWindowSize = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "mainWindowSize", 8f, "Main window row size (4-16)");
			integrationWithDSPStarMapMemo = ((BaseUnityPlugin)this).Config.Bind<bool>("Integration", "integrationWithDSPStarMapMemo", false, "Display icons set by DSPStarMapMemo");
			integrationWithLSTM = ((BaseUnityPlugin)this).Config.Bind<bool>("Integration", "integrationWithLSTM", false, "open LSTM from context menu");
			integrationWithCruiseAssist = ((BaseUnityPlugin)this).Config.Bind<bool>("Integration", "integrationWithCruiseAssist", false, "set CruiseAssist from context menu");
			val.PatchAll(typeof(Patch));
			val.PatchAll(typeof(MyWindowCtl.Patch));
			val.PatchAll(typeof(StarDistance.Patch));
		}

		public static void Log(string str)
		{
			Logger.LogInfo((object)str);
		}

		public static void UniverseExplorationRequired()
		{
			UIMessageBox.Show(Localization.Translate("Upgrades Required"), Localization.Translate("To use this feature, Universe Exploration 4 is required."), "OK", 0);
		}

		public static void LocatePlanet(int planetId, int starId = 0)
		{
			if (planetId <= 0 && starId <= 0)
			{
				return;
			}
			if (GameMain.history.universeObserveLevel >= 4)
			{
				UIRoot.instance.uiGame.ShutPlayerInventory();
				UIRoot.instance.uiGame.ShutAllFunctionWindow();
				UIRoot.instance.uiGame.OpenStarmap();
				int num = ((planetId > 0) ? (planetId / 100) : starId);
				int num2 = ((planetId > 0) ? (planetId % 100) : 0);
				UIStarmap starmap = UIRoot.instance.uiGame.starmap;
				starmap.focusPlanet = null;
				starmap.focusStar = starmap.starUIs[num - 1];
				starmap.OnCursorFunction2Click(0);
				if (num2 > 0 && (Object)(object)starmap.focusStar == (Object)null)
				{
					starmap.focusPlanet = starmap.planetUIs[num2 - 1];
					starmap.OnCursorFunction2Click(0);
					starmap.focusPlanet = starmap.planetUIs[num2 - 1];
					starmap.focusStar = null;
				}
			}
			else
			{
				UniverseExplorationRequired();
			}
		}

		public static void TogglePlanetFinderWindow()
		{
			if (((ManualBehaviour)planetFinder).active)
			{
				((ManualBehaviour)planetFinder)._Close();
			}
			else
			{
				planetFinder.SetUpAndOpen();
			}
		}

		public static void AddRecentPlanet(PlanetData planetData)
		{
			if (recentPlanets.Contains(planetData))
			{
				recentPlanets.Remove(planetData);
			}
			recentPlanets.Insert(0, planetData);
			if (recentPlanets.Count > 99)
			{
				recentPlanets.RemoveAt(recentPlanets.Count - 1);
			}
		}

		public static bool IsFavPlanet(PlanetData planetData)
		{
			string overrideName = planetData.overrideName;
			if (string.IsNullOrEmpty(overrideName))
			{
				return false;
			}
			if (overrideName.Contains("★"))
			{
				return true;
			}
			return false;
		}

		public static void SetFavPlanet(PlanetData planetData, bool flag)
		{
			if (flag)
			{
				if (!IsFavPlanet(planetData))
				{
					string displayName = planetData.displayName;
					displayName += "★";
					planetData.overrideName = displayName;
					GameScenarioLogic gameScenario = GameMain.gameScenario;
					if (gameScenario != null)
					{
						gameScenario.NotifyOnPlanetNameChange();
					}
					planetData.NotifyOnDisplayNameChange();
					GameMain.galaxy.NotifyAstroNameChange();
				}
			}
			else
			{
				if (!IsFavPlanet(planetData))
				{
					return;
				}
				string overrideName = planetData.overrideName;
				overrideName = overrideName.Replace("★", "").Trim();
				if (!string.Equals(overrideName, planetData.overrideName))
				{
					if (string.Equals(overrideName, planetData.name))
					{
						planetData.overrideName = "";
					}
					else
					{
						planetData.overrideName = overrideName;
					}
					GameScenarioLogic gameScenario2 = GameMain.gameScenario;
					if (gameScenario2 != null)
					{
						gameScenario2.NotifyOnPlanetNameChange();
					}
					planetData.NotifyOnDisplayNameChange();
					GameMain.galaxy.NotifyAstroNameChange();
				}
			}
		}

		private void Update()
		{
			//IL_0028: 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)
			if (GameMain.isRunning && !GameMain.isPaused && !GameMain.instance.isMenuDemo && !VFInput.inputing)
			{
				KeyboardShortcut value = mainWindowHotkey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					TogglePlanetFinderWindow();
				}
				else if (VFInput._closePanelE && ((ManualBehaviour)planetFinder).active)
				{
					((ManualBehaviour)planetFinder)._Close();
				}
			}
		}

		private void FixedUpdate()
		{
			if ((Object)(object)planetFinder != (Object)null && planetFinder.isPointEnter)
			{
				VFInput.inScrollView = true;
			}
		}

		public static void CreateUI()
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			Button button = UIRoot.instance.uiGame.planetGlobe.button2;
			UIButton dfIconButton = UIRoot.instance.uiGame.gameMenu.dfIconButton;
			object obj;
			if (dfIconButton == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = ((Component)dfIconButton).transform.Find("icon");
				if (obj2 == null)
				{
					obj = null;
				}
				else
				{
					Image component = ((Component)obj2).GetComponent<Image>();
					obj = ((component != null) ? component.sprite : null);
				}
			}
			Sprite sprite = (Sprite)obj;
			Button val = Object.Instantiate<Button>(button, ((Component)button).transform.parent);
			panelButtonGO = ((val != null) ? ((Component)val).gameObject : null);
			Transform transform = panelButtonGO.transform;
			RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			UIButton component2 = panelButtonGO.GetComponent<UIButton>();
			Transform obj3 = panelButtonGO.transform.Find("button-2/icon");
			Image val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<Image>() : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.sprite = sprite;
			}
			if ((Object)(object)panelButtonGO != (Object)null && (Object)(object)component2 != (Object)null)
			{
				((Object)panelButtonGO).name = "open-planet-finder";
				((Transform)val2).localScale = new Vector3(0.6f, 0.6f, 0.6f);
				val2.anchoredPosition3D = new Vector3(133f, -88f, 0f);
				((UnityEventBase)val.onClick).RemoveAllListeners();
				component2.onClick += OnShowWindowButtonClick;
				component2.tips.tipTitle = "Planet Finder";
				component2.tips.tipText = "open/close Planet Finder Window";
				component2.tips.corner = 9;
				component2.tips.offset = new Vector2(-20f, -20f);
				Transform transform2 = panelButtonGO.transform;
				val2 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
				panelButtonGO.SetActive(showButtonInMainPanel.Value);
				showButtonInMainPanel.SettingChanged += delegate
				{
					panelButtonGO.SetActive(showButtonInMainPanel.Value);
				};
			}
			UIButton northButton = UIRoot.instance.uiGame.starmap.northButton;
			Transform val4 = ((northButton != null) ? ((Component)northButton).transform.parent : null);
			if ((Object)(object)val4 != (Object)null)
			{
				starmapButtonGO = Object.Instantiate<GameObject>(panelButtonGO, val4);
				starmapButtonGO.SetActive(showButtonInStarmap.Value);
				component2 = starmapButtonGO.GetComponent<UIButton>();
				component2.onClick += OnShowWindowButtonClick;
				component2.tips.corner = 7;
				component2.tips.offset = new Vector2(25f, -8f);
				Transform transform3 = starmapButtonGO.transform;
				val2 = (RectTransform)(object)((transform3 is RectTransform) ? transform3 : null);
				val2.anchorMin = new Vector2(1f, 0f);
				val2.anchorMax = new Vector2(1f, 0f);
				val2.pivot = new Vector2(1f, 0f);
				val2.anchoredPosition = new Vector2(-16f, 48f);
				showButtonInStarmap.SettingChanged += delegate
				{
					starmapButtonGO.SetActive(showButtonInStarmap.Value);
				};
			}
			UIPlanetDetail planetDetail = UIRoot.instance.uiGame.planetDetail;
			val4 = ((planetDetail != null) ? ((Component)planetDetail).transform : null);
			if ((Object)(object)val4 != (Object)null)
			{
				UIButton obj4 = Util.MakeHiliteTextButton("★", 18f, 18f);
				obj4.onClick += OnStarmapFavButtonClick;
				Util.NormalizeRectWithTopLeft((Component)(object)obj4, 218f, 38f, val4);
				favBtnGO = ((Component)obj4).gameObject;
				((Object)favBtnGO).name = "planetfinder-fav";
				favBtnGO.SetActive(showFavButtonInStarmap.Value);
				showFavButtonInStarmap.SettingChanged += delegate
				{
					favBtnGO.SetActive(showFavButtonInStarmap.Value);
				};
			}
		}

		public static void OnStarmapFavButtonClick(int obj)
		{
			UIPlanetDetail planetDetail = UIRoot.instance.uiGame.planetDetail;
			PlanetData planet = planetDetail.planet;
			SetFavPlanet(planet, !IsFavPlanet(planet));
			favBtnGO.GetComponent<UIButton>().highlighted = IsFavPlanet(planet);
			if (!planetDetail.nameInput.isFocused)
			{
				planetDetail.nameInput.text = planetDetail.planet.displayName;
			}
		}

		public static void OnShowWindowButtonClick(int obj)
		{
			TogglePlanetFinderWindow();
		}
	}
	public class RecyclingListView : MonoBehaviour
	{
		public delegate void ItemDelegate(MonoBehaviour item, int rowIndex);

		[Tooltip("Prefab for all the child view objects in the list")]
		public MonoBehaviour ChildPrefab;

		[Tooltip("The amount of vertical padding to add between items")]
		public float RowPadding = 4f;

		[Tooltip("Minimum height to pre-allocate list items for. Use to prevent allocations on resizing.")]
		public float PreAllocHeight = 100f;

		protected int rowCount;

		public ItemDelegate ItemCallback;

		public ScrollRect scrollRect;

		public MonoBehaviour[] childItems;

		protected int childBufferStart;

		protected int sourceDataRowStart;

		protected bool ignoreScrollChange;

		protected float previousBuildHeight;

		protected const int rowsAboveBelow = 1;

		public float VerticalNormalizedPosition
		{
			get
			{
				return scrollRect.verticalNormalizedPosition;
			}
			set
			{
				scrollRect.verticalNormalizedPosition = value;
			}
		}

		public int RowCount
		{
			get
			{
				return rowCount;
			}
			set
			{
				if (rowCount != value)
				{
					rowCount = value;
					ignoreScrollChange = true;
					UpdateContentHeight();
					ignoreScrollChange = false;
					ReorganiseContent(clearContents: true);
				}
			}
		}

		public virtual void Refresh()
		{
			ReorganiseContent(clearContents: true);
		}

		public virtual void Refresh(int rowStart, int count)
		{
			int num = sourceDataRowStart + childItems.Length;
			for (int i = 0; i < count; i++)
			{
				int num2 = rowStart + i;
				if (num2 >= sourceDataRowStart && num2 < num)
				{
					int num3 = WrapChildIndex(childBufferStart + num2 - sourceDataRowStart);
					if ((Object)(object)childItems[num3] != (Object)null)
					{
						UpdateChild(childItems[num3], num2);
					}
				}
			}
		}

		public virtual void Refresh(MonoBehaviour item)
		{
			for (int i = 0; i < childItems.Length; i++)
			{
				int num = WrapChildIndex(childBufferStart + i);
				if ((Object)(object)childItems[num] != (Object)null && (Object)(object)childItems[num] == (Object)(object)item)
				{
					UpdateChild(childItems[i], sourceDataRowStart + i);
					break;
				}
			}
		}

		public virtual void Clear()
		{
			RowCount = 0;
		}

		public virtual void ScrollToRow(int row)
		{
			scrollRect.verticalNormalizedPosition = GetRowScrollPosition(row);
		}

		public float GetRowScrollPosition(int row)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			float num = ((float)row + 0.5f) * RowHeight();
			float num2 = ViewportHeight();
			float num3 = num2 * 0.5f;
			float num4 = Mathf.Max(0f, num - num3);
			float num5 = num4 + num2;
			float y = scrollRect.content.sizeDelta.y;
			if (num5 > y)
			{
				num4 = Mathf.Max(0f, num4 - (num5 - y));
			}
			return Mathf.InverseLerp(y - num2, 0f, num4);
		}

		public MonoBehaviour GetRowItem(int row)
		{
			if (childItems != null && row >= sourceDataRowStart && row < sourceDataRowStart + childItems.Length && row < rowCount)
			{
				return childItems[WrapChildIndex(childBufferStart + row - sourceDataRowStart)];
			}
			return null;
		}

		protected virtual void Awake()
		{
		}

		protected virtual bool CheckChildItems()
		{
			float num = Mathf.Max(ViewportHeight(), PreAllocHeight);
			bool flag = childItems == null || num > previousBuildHeight;
			if (flag)
			{
				int num2 = Mathf.RoundToInt(0.5f + num / RowHeight());
				num2 += 2;
				if (childItems == null)
				{
					childItems = (MonoBehaviour[])(object)new MonoBehaviour[num2];
				}
				else if (num2 > childItems.Length)
				{
					Array.Resize(ref childItems, num2);
				}
				for (int i = 0; i < childItems.Length; i++)
				{
					if ((Object)(object)childItems[i] == (Object)null)
					{
						childItems[i] = Object.Instantiate<MonoBehaviour>(ChildPrefab);
					}
					((Transform)((Component)childItems[i]).GetComponent<RectTransform>()).SetParent((Transform)(object)scrollRect.content, false);
					((Component)childItems[i]).gameObject.SetActive(false);
				}
				previousBuildHeight = num;
			}
			return flag;
		}

		protected virtual void OnEnable()
		{
			ScrollRect obj = scrollRect;
			if (obj != null)
			{
				((UnityEvent<Vector2>)(object)obj.onValueChanged).AddListener((UnityAction<Vector2>)OnScrollChanged);
			}
			ignoreScrollChange = false;
		}

		protected virtual void OnDisable()
		{
			ScrollRect obj = scrollRect;
			if (obj != null)
			{
				((UnityEvent<Vector2>)(object)obj.onValueChanged).RemoveListener((UnityAction<Vector2>)OnScrollChanged);
			}
		}

		protected virtual void OnScrollChanged(Vector2 normalisedPos)
		{
			if (!ignoreScrollChange)
			{
				ReorganiseContent(clearContents: false);
			}
		}

		protected virtual void ReorganiseContent(bool clearContents)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (clearContents)
			{
				scrollRect.StopMovement();
				scrollRect.verticalNormalizedPosition = 1f;
			}
			bool num = CheckChildItems() || clearContents;
			float y = ((Transform)scrollRect.content).localPosition.y;
			Transform transform = ((Component)scrollRect).transform;
			Rect rect = ((RectTransform)((transform is RectTransform) ? transform : null)).rect;
			int num2 = (int)((y - ((Rect)(ref rect)).height / 2f) / RowHeight()) - 1;
			int num3 = num2 - sourceDataRowStart;
			if (num || Mathf.Abs(num3) >= childItems.Length)
			{
				sourceDataRowStart = num2;
				childBufferStart = 0;
				int num4 = num2;
				MonoBehaviour[] array = childItems;
				foreach (MonoBehaviour child in array)
				{
					UpdateChild(child, num4++);
				}
			}
			else
			{
				if (num3 == 0)
				{
					return;
				}
				int num5 = (childBufferStart + num3) % childItems.Length;
				if (num3 < 0)
				{
					for (int j = 1; j <= -num3; j++)
					{
						int num6 = WrapChildIndex(childBufferStart - j);
						int rowIdx = sourceDataRowStart - j;
						UpdateChild(childItems[num6], rowIdx);
					}
				}
				else
				{
					int num7 = childBufferStart + childItems.Length - 1;
					int num8 = sourceDataRowStart + childItems.Length - 1;
					for (int k = 1; k <= num3; k++)
					{
						int num9 = WrapChildIndex(num7 + k);
						int rowIdx2 = num8 + k;
						UpdateChild(childItems[num9], rowIdx2);
					}
				}
				sourceDataRowStart = num2;
				childBufferStart = num5;
			}
		}

		private int WrapChildIndex(int idx)
		{
			while (idx < 0)
			{
				idx += childItems.Length;
			}
			return idx % childItems.Length;
		}

		private float RowHeight()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float rowPadding = RowPadding;
			Rect rect = ((Component)ChildPrefab).GetComponent<RectTransform>().rect;
			return rowPadding + ((Rect)(ref rect)).height;
		}

		private float ViewportHeight()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)scrollRect).transform;
			Rect rect = ((RectTransform)((transform is RectTransform) ? transform : null)).rect;
			return ((Rect)(ref rect)).height * 1.5f;
		}

		protected virtual void UpdateChild(MonoBehaviour child, int rowIdx)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (rowIdx < 0 || rowIdx >= rowCount)
			{
				((Component)child).gameObject.SetActive(false);
			}
			else if (ItemCallback != null)
			{
				Rect rect = ((Component)ChildPrefab).GetComponent<RectTransform>().rect;
				Vector2 pivot = ((Component)ChildPrefab).GetComponent<RectTransform>().pivot;
				float num = RowHeight() * (float)rowIdx + (1f - pivot.y) * ((Rect)(ref rect)).height;
				float num2 = 0f + pivot.x * ((Rect)(ref rect)).width;
				((Component)child).GetComponent<RectTransform>().anchoredPosition = new Vector2(num2, 0f - num);
				ItemCallback(child, rowIdx);
				((Component)child).gameObject.SetActive(true);
			}
		}

		protected virtual void UpdateContentHeight()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0042: 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)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = ((Component)ChildPrefab).GetComponent<RectTransform>().rect;
			float num = ((Rect)(ref rect)).height * (float)rowCount + (float)(rowCount - 1) * RowPadding;
			Vector2 sizeDelta = scrollRect.content.sizeDelta;
			scrollRect.content.sizeDelta = new Vector2(sizeDelta.x, num);
		}

		protected virtual void DisableAllChildren()
		{
			if (childItems != null)
			{
				for (int i = 0; i < childItems.Length; i++)
				{
					((Component)childItems[i]).gameObject.SetActive(false);
				}
			}
		}
	}
	public class StarDistance
	{
		public static class Patch
		{
			[HarmonyPrefix]
			[HarmonyPatch(typeof(GameMain), "Begin")]
			public static void GameMain_Begin_Prefix()
			{
				if (_distances != null)
				{
					_distances.Clear();
				}
				_distances = new Dictionary<int, Dictionary<int, float>>(GameMain.galaxy.starCount);
				InitDistances();
			}
		}

		public static Dictionary<int, Dictionary<int, float>> _distances;

		public static float DistanceFromHere(int star, int nearStar = 0)
		{
			int num = ((GameMain.localPlanet == null) ? nearStar : GameMain.localPlanet.star.id);
			if (num != 0)
			{
				return Distance(star, num);
			}
			return -1f;
		}

		public static float Distance(int star, int star2)
		{
			if (star == star2)
			{
				return 0f;
			}
			int key;
			int key2;
			if (star > star2)
			{
				key = star2;
				key2 = star;
			}
			else
			{
				key = star;
				key2 = star2;
			}
			_distances.TryGetValue(key, out var value);
			if (value != null)
			{
				value.TryGetValue(key2, out var value2);
				return value2;
			}
			return -1f;
		}

		internal static void InitDistances()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			_distances.Clear();
			if (GameMain.instance.isMenuDemo)
			{
				return;
			}
			GalaxyData galaxy = GameMain.galaxy;
			for (int i = 0; i < galaxy.starCount; i++)
			{
				StarData val = galaxy.stars[i];
				Dictionary<int, float> dictionary = new Dictionary<int, float>(galaxy.starCount - i);
				for (int j = i + 1; j < galaxy.starCount; j++)
				{
					StarData val2 = galaxy.stars[j];
					VectorLF3 val3 = val.uPosition - val2.uPosition;
					double magnitude = ((VectorLF3)(ref val3)).magnitude;
					dictionary.Add(value: (!(magnitude < 2400000.0)) ? ((float)(magnitude / 2400000.0)) : 1f, key: val2.id);
				}
				_distances.Add(val.id, dictionary);
			}
		}
	}
	public class UIConfigWindow : ManualBehaviour, MyWindow
	{
		public RectTransform windowTrans;

		public RectTransform tab1;

		public UIButton tabBtn1;

		public static UIConfigWindow CreateWindow()
		{
			return MyWindowCtl.CreateWindow<UIConfigWindow>("PLFDConfigWindow", "PlanetFinder Config");
		}

		public void TryClose()
		{
			((ManualBehaviour)this)._Close();
		}

		public bool isFunctionWindow()
		{
			return true;
		}

		public void OpenWindow()
		{
			MyWindowCtl.OpenWindow((ManualBehaviour)(object)this);
		}

		public override void _OnCreate()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			windowTrans = MyWindowCtl.GetRectTransform((ManualBehaviour)(object)this);
			windowTrans.sizeDelta = new Vector2(640f, 376f);
			CreateUI();
		}

		internal void CreateUI()
		{
			RectTransform base_ = windowTrans;
			float y_ = 54f;
			float x_ = 36f;
			float tabx_ = 36f;
			int tabIndex_ = 1;
			tab1 = AddTab("General", out tabBtn1);
			((Component)tabBtn1).gameObject.SetActive(false);
			base_ = tab1;
			y_ = 0f;
			x_ = 0f;
			RectTransform rect_2 = MyKeyBinder.CreateKeyBinder(PLFN.mainWindowHotkey, "Main Hotkey");
			AddElement(rect_2, 90f);
			rect_2 = MyCheckBox.CreateCheckBox(PLFN.showButtonInMainPanel, "Show Button In Main Panel");
			AddElement(rect_2, 26f);
			rect_2 = MyCheckBox.CreateCheckBox(PLFN.showButtonInStarmap, "Show Button In Starmap");
			AddElement(rect_2, 26f);
			Text val = CreateText("Window Size");
			Transform transform = ((Component)val).transform;
			AddElement((RectTransform)(object)((transform is RectTransform) ? transform : null), 32f);
			rect_2 = MySlider.CreateSlider(PLFN.mainWindowSize, 4f, 12f, "0", 200f);
			AddElement(rect_2, 26f);
			rect_2 = MyCheckBox.CreateCheckBox(PLFN.showPowerState, "Show Power State In List");
			AddElement(rect_2, 26f);
			rect_2 = MyCheckBox.CreateCheckBox(PLFN.showPrefix, "Show [GAS] [TL] Prefix");
			AddElement(rect_2, 26f);
			x_ = 290f;
			y_ = 0f;
			rect_2 = MyCheckBox.CreateCheckBox(PLFN.showFavButtonInStarmap, "Show Fav Button In Starmap");
			AddElement(rect_2, 26f);
			if (PLFN.aDSPStarMapMemoIntg.canGetSignalIconId)
			{
				rect_2 = MyCheckBox.CreateCheckBox(PLFN.integrationWithDSPStarMapMemo, "Integration With DSPStarMapMemo");
				AddElement(rect_2, 22f);
				x_ += 32f;
				val = CreateText("Display Icons / Search Memo");
				val.fontSize = 14;
				AddElement(((Graphic)val).rectTransform, 24f);
				x_ -= 32f;
			}
			if (PLFN.aLSTMIntg.canOpenPlanetId)
			{
				rect_2 = MyCheckBox.CreateCheckBox(PLFN.integrationWithLSTM, "Integration With LSTM");
				AddElement(rect_2, 22f);
				x_ += 32f;
				val = CreateText("Open LSTM From Context Panel");
				val.fontSize = 14;
				AddElement(((Graphic)val).rectTransform, 24f);
				x_ -= 32f;
			}
			if (PLFN.aCruiseAssistIntg.canSelectPlanet)
			{
				rect_2 = MyCheckBox.CreateCheckBox(PLFN.integrationWithCruiseAssist, "Integration With CruiseAssist");
				AddElement(rect_2, 22f);
				x_ += 32f;
				val = CreateText("Set CruiseAssist From Context Panel");
				val.fontSize = 14;
				AddElement(((Graphic)val).rectTransform, 24f);
				x_ -= 32f;
			}
			y_ = 0f;
			x_ = 0f;
			void AddElement(RectTransform rect_, float height)
			{
				if ((Object)(object)rect_ != (Object)null)
				{
					Util.NormalizeRectWithTopLeft((Component)(object)rect_, x_, y_, (Transform)(object)base_);
				}
				y_ += height;
			}
			RectTransform AddTab(string label, out UIButton outBtn)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: 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)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				GameObject val3 = new GameObject();
				RectTransform val4 = val3.AddComponent<RectTransform>();
				Util.NormalizeRectWithMargin((Component)(object)val4, 82f, 36f, 0f, 0f, (Transform)(object)windowTrans);
				((Object)val3).name = "tab-" + tabIndex_;
				UIButton val5 = Object.Instantiate<UIButton>(UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel.orbitButtons[0]);
				Util.NormalizeRectWithTopLeft((Component)(object)val5, tabx_, 54f, (Transform)(object)windowTrans).sizeDelta = new Vector2(100f, 24f);
				((Component)((Component)val5).transform.Find("frame")).gameObject.SetActive(false);
				if (val5.transitions.Length >= 3)
				{
					val5.transitions[0].normalColor = new Color(0.1f, 0.1f, 0.1f, 0.68f);
					val5.transitions[0].highlightColorOverride = new Color(0.9906f, 0.5897f, 0.3691f, 0.4f);
					val5.transitions[1].normalColor = new Color(1f, 1f, 1f, 0.6f);
					val5.transitions[1].highlightColorOverride = new Color(0.2f, 0.1f, 0.1f, 0.9f);
				}
				Text component = ((Component)((Component)val5).transform.Find("Text")).GetComponent<Text>();
				component.text = label;
				component.fontSize = 16;
				val5.data = tabIndex_;
				tabIndex_++;
				tabx_ += 100f;
				outBtn = val5;
				return val4;
			}
			Text CreateText(string label_)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				Text val2 = Object.Instantiate<Text>(MyWindowCtl.GetTitleText((ManualBehaviour)(object)this));
				((Object)((Component)val2).gameObject).name = "label";
				val2.text = label_;
				((Graphic)val2).color = new Color(1f, 1f, 1f, 0.38f);
				Transform transform2 = ((Component)val2).transform;
				((RectTransform)((transform2 is RectTransform) ? transform2 : null)).sizeDelta = new Vector2(val2.preferredWidth + 40f, 30f);
				return val2;
			}
		}

		public override void _OnDestroy()
		{
		}

		public override bool _OnInit()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			windowTrans.anchoredPosition = new Vector2(0f, 0f);
			return true;
		}

		public override void _OnFree()
		{
		}

		public override void _OnRegEvent()
		{
		}

		public override void _OnUnregEvent()
		{
		}

		public override void _OnOpen()
		{
		}

		public override void _OnClose()
		{
		}

		public override void _OnUpdate()
		{
			if (VFInput.escape && !VFInput.inputing)
			{
				VFInput.UseEscape();
				((ManualBehaviour)this)._Close();
			}
		}
	}
	public class UIItemSelection : MonoBehaviour
	{
		public static UIButton buttonPrefab;

		public static Sprite emptyImage;

		public UIPlanetFinderWindow planetFinderWindow;

		public RectTransform rectTrans;

		public List<UIButton> buttons;

		public List<string> buttonNames;

		public static int[] additionalMaterials = new int[6] { 1000, 1116, 0, 1120, 1121, 1011 };

		public HashSet<int> items;

		public int lastSelectedItemId;

		public static UIButton CreatePrefab()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			UIButton val = null;
			UIButton[] buildingWarnButtons = UIRoot.instance.optionWindow.buildingWarnButtons;
			if (buildingWarnButtons != null && buildingWarnButtons.Length != 0)
			{
				val = Object.Instantiate<UIButton>(buildingWarnButtons[0]);
				val.onClick += null;
				((Object)((Component)val).gameObject).name = "item-button";
				val.tips.tipText = "";
				val.tips.tipTitle = "";
				val.tips.delay = 0.6f;
				val.tips.corner = 8;
				Transform transform = ((Component)val).transform;
				Transform obj = ((transform is RectTransform) ? transform : null);
				((RectTransform)obj).sizeDelta = new Vector2(28f, 28f);
				foreach (Transform item in obj)
				{
					Transform val2 = item;
					((RectTransform)((val2 is RectTransform) ? val2 : null)).sizeDelta = new Vector2(28f, 28f);
					if (((Object)((Component)val2).gameObject).name == "image")
					{
						((Graphic)((Component)val2).GetComponent<Image>()).color = Color.white;
					}
				}
				if (val.transitions.Length > 1)
				{
					val.transitions[1].mouseoverColor = Color.white;
					val.transitions[1].normalColor = Color.white;
				}
			}
			return val;
		}

		public static UIButton CreateSelectButton(UIItemSelection owner)
		{
			if ((Object)(object)buttonPrefab == (Object)null)
			{
				Image iconTagImage = UIRoot.instance.uiGame.beltWindow.iconTagImage;
				emptyImage = ((iconTagImage != null) ? iconTagImage.sprite : null);
				buttonPrefab = CreatePrefab();
			}
			UIButton obj = Object.Instantiate<UIButton>(buttonPrefab);
			obj.onClick += owner.OnSelectButtonClick;
			obj.onRightClick += owner.OnSelectButtonRightClick;
			return obj;
		}

		public static void SetButtonIcon(UIButton btn, Sprite sprite, string name, int obj)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Transform obj2 = ((Component)btn).transform.Find("image");
			Image val = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
			if ((Object)(object)val != (Object)null)
			{
				val.sprite = sprite;
			}
			btn.data = obj;
			if (name != null)
			{
				btn.tips.tipTitle = name;
				btn.tips.corner = 9;
				btn.tips.offset = new Vector2(-26f, 4f);
			}
		}

		public Sprite GetIconForItemId(int itemId)
		{
			if (itemId == 0)
			{
				return null;
			}
			foreach (UIButton button in buttons)
			{
				if (button.data == itemId)
				{
					Transform obj = ((Component)button).transform.Find("image");
					Image val = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
					if ((Object)(object)val != (Object)null)
					{
						return val.sprite;
					}
				}
			}
			return null;
		}

		public string MouseOverButtonName()
		{
			for (int i = 0; i < buttons.Count; i++)
			{
				if (buttons[i]._isPointerEnter)
				{
					return buttonNames[i];
				}
			}
			return null;
		}

		public static UIItemSelection CreateInstance()
		{
			UIItemSelection uIItemSelection = Util.CreateGameObject<UIItemSelection>("item-selection", 500f, 30f);
			uIItemSelection.Init();
			return uIItemSelection;
		}

		private void Init()
		{
			items = new HashSet<int>();
			ref RectTransform reference = ref rectTrans;
			Transform transform = ((Component)this).transform;
			reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			float top = 4f;
			float num = 0f;
			buttons = new List<UIButton>(40);
			buttonNames = new List<string>(40);
			for (int i = 1; i < 15; i++)
			{
				VeinProto val = ((ProtoSet<VeinProto>)(object)LDB.veins).Select(i);
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val.MiningItem);
				if (val != null && val2 != null)
				{
					UIButton val3 = CreateSelectButton(this);
					Util.NormalizeRectWithTopLeft((Component)(object)val3, num, top, (Transform)(object)rectTrans);
					((Selectable)val3.button).interactable = true;
					SetButtonIcon(val3, val.iconSprite, ((Proto)val).name, ((Proto)val).ID);
					buttons.Add(val3);
					buttonNames.Add(((Proto)val).name);
					num += 30f;
				}
			}
			num += 6f;
			int[] array = additionalMaterials;
			foreach (int num2 in array)
			{
				if (num2 == 0)
				{
					num += 6f;
					continue;
				}
				ItemProto val4 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(num2);
				if (val4 != null)
				{
					UIButton val5 = CreateSelectButton(this);
					Util.NormalizeRectWithTopLeft((Component)(object)val5, num, top, (Transform)(object)rectTrans);
					((Selectable)val5.button).interactable = true;
					SetButtonIcon(val5, val4.iconSprite, ((Proto)val4).name, num2);
					buttons.Add(val5);
					buttonNames.Add(((Proto)val4).name);
					num += 30f;
				}
			}
		}

		public void RefreshButtons()
		{
			foreach (UIButton button in buttons)
			{
				button.highlighted = items.Contains(button.data);
			}
		}

		public void ToggleItemSelected(int itemId, bool multiple = false)
		{
			if (items.Contains(itemId))
			{
				if (!multiple)
				{
					items.Clear();
					lastSelectedItemId = 0;
				}
				else
				{
					items.Remove(itemId);
					if (lastSelectedItemId == itemId)
					{
						if (items.Count > 0)
						{
							foreach (int item in items)
							{
								lastSelectedItemId = item;
							}
						}
						else
						{
							lastSelectedItemId = 0;
						}
					}
				}
			}
			else
			{
				if (!multiple)
				{
					items.Clear();
				}
				items.Add(itemId);
				lastSelectedItemId = itemId;
			}
			RefreshButtons();
			planetFinderWindow.SetUpData();
		}

		public void OnSelectButtonClick(int obj)
		{
			if (obj != 0)
			{
				ToggleItemSelected(obj, VFInput.shift);
			}
		}

		public void OnSelectButtonRightClick(int obj)
		{
		}

		public int NextTargetItemId(int targetItemId, bool includesEmpty = false)
		{
			if (items.Count == 0)
			{
				return targetItemId;
			}
			int num = int.MaxValue;
			int num2 = int.MaxValue;
			foreach (int item in items)
			{
				if (targetItemId >= item && num > item)
				{
					num = item;
				}
				if (targetItemId < item && num2 > item)
				{
					num2 = item;
				}
			}
			if (num2 != int.MaxValue)
			{
				return num2;
			}
			if (includesEmpty)
			{
				return 0;
			}
			if (num != int.MaxValue)
			{
				return num;
			}
			return targetItemId;
		}
	}
	public class UIPlanetFinderListItem : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
	{
		public static Sprite circleSprite;

		public static Color valueTextNormalColor;

		public static Color valueTextMiningColor;

		public UIPlanetFinderWindow window;

		public bool firstRefleshed;

		public PlanetListData listData;

		public PlanetData planetData;

		public StarData starData;

		public string distanceStr;

		public Color planetColor;

		private int _itemId;

		[SerializeField]
		public Text nameText;

		[SerializeField]
		public Text valueText;

		[SerializeField]
		public Text valueSketchText;

		[SerializeField]
		public Image labelIcon;

		[SerializeField]
		public Image veinIcon;

		[SerializeField]
		public Sprite iconHide;

		[SerializeField]
		public UIButton iconButton;

		[SerializeField]
		public UIButton locateBtn;

		[SerializeField]
		public GameObject baseObj;

		public StringBuilder sb;

		public static int veinCount = 15;

		public bool disableUIAction;

		public string planetName
		{
			get
			{
				return nameText.text;
			}
			set
			{
				nameText.text = value;
			}
		}

		public int itemId
		{
			get
			{
				return _itemId;
			}
			set
			{
				if (_itemId != value)
				{
					_itemId = value;
					sb = ((_itemId == 7) ? window.sbOil : window.sb);
					veinIcon.sprite = window.itemSelection.GetIconForItemId(_itemId);
					((Behaviour)veinIcon).enabled = (Object)(object)veinIcon.sprite != (Object)null;
				}
			}
		}

		public static UIPlanetFinderListItem CreateListViewPrefab()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: 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_03a7: Unknown result type (might be due to invalid IL or missing references)
			UIPlanetFinderListItem uIPlanetFinderListItem = Util.CreateGameObject<UIPlanetFinderListItem>("list-item", 600f, 24f);
			Image val = Util.CreateGameObject<Image>("list-item", 600f, 24f);
			((Component)val).gameObject.SetActive(true);
			RectTransform val2 = Util.NormalizeRectWithTopLeft((Component)(object)val, 0f, 0f, ((Component)uIPlanetFinderListItem).transform);
			uIPlanetFinderListItem.baseObj = ((Component)val).gameObject;
			((Graphic)val).color = new Color(0.2f, 0.2f, 0.2f, 0.1f);
			Transform transform = ((Component)uIPlanetFinderListItem).transform;
			((RectTransform)((transform is RectTransform) ? transform : null)).sizeDelta = new Vector2(600f, 24f);
			val2.sizeDelta = new Vector2(600f, 24f);
			((Transform)val2).localScale = Vector3.one;
			UIResAmountEntry val3 = Object.Instantiate<UIResAmountEntry>(UIRoot.instance.uiGame.planetDetail.entryPrafab, (Transform)(object)val2);
			((Component)val3).gameObject.SetActive(true);
			float num = 0f;
			float num2 = 22f;
			UIButton val4 = Util.MakeIconButtonB(Util.astroIndicatorIcon, 22f);
			if ((Object)(object)val4 != (Object)null)
			{
				((Object)((Component)val4).gameObject).name = "locate-btn";
				Util.NormalizeRectWithTopLeft((Component)(object)val4, 538f - num, 3f, (Transform)(object)val2);
				val4.tips.tipTitle = Localization.Translate("Locate Planet");
				val4.tips.tipText = Localization.Translate("Show the planet on the starmap.");
				val4.tips.corner = 3;
				val4.tips.offset = new Vector2(18f, -20f);
				uIPlanetFinderListItem.locateBtn = val4;
			}
			uIPlanetFinderListItem.nameText = val3.labelText;
			uIPlanetFinderListItem.nameText.text = "";
			uIPlanetFinderListItem.nameText.fontSize = 16;
			((Graphic)uIPlanetFinderListItem.nameText).rectTransform.anchoredPosition = new Vector2(8f + num2, 0f);
			uIPlanetFinderListItem.valueText = val3.valueText;
			uIPlanetFinderListItem.valueText.text = "";
			((Graphic)uIPlanetFinderListItem.valueText).color = ((Graphic)uIPlanetFinderListItem.nameText).color;
			uIPlanetFinderListItem.valueText.supportRichText = true;
			Util.NormalizeRectWithTopLeft((Component)(object)uIPlanetFinderListItem.valueText, 380f - num - num2, 2f).sizeDelta = new Vector2(100f, 24f);
			valueTextNormalColor = ((Graphic)uIPlanetFinderListItem.valueText).color;
			valueTextMiningColor = new Color(0.1f, 0.7f, 0.8f, valueTextNormalColor.a);
			uIPlanetFinderListItem.valueSketchText = Object.Instantiate<Text>(uIPlanetFinderListItem.valueText, ((Component)uIPlanetFinderListItem.valueText).transform.parent);
			((Object)((Component)uIPlanetFinderListItem.valueSketchText).gameObject).name = "valueSketchText";
			uIPlanetFinderListItem.valueSketchText.alignment = (TextAnchor)3;
			Util.NormalizeRectWithTopLeft((Component)(object)uIPlanetFinderListItem.valueSketchText, 504f - num - num2, 2f).sizeDelta = new Vector2(24f, 24f);
			uIPlanetFinderListItem.veinIcon = val3.iconImage;
			if ((Object)(object)uIPlanetFinderListItem.veinIcon != (Object)null)
			{
				Util.NormalizeRectWithTopLeft((Component)(object)uIPlanetFinderListItem.veinIcon, 482f - num - num2, 2f);
				((Behaviour)uIPlanetFinderListItem.veinIcon).enabled = false;
				uIPlanetFinderListItem.labelIcon = Object.Instantiate<Image>(uIPlanetFinderListItem.veinIcon, (Transform)(object)val2);
				((Object)((Component)uIPlanetFinderListItem.labelIcon).gameObject).name = "labelIcon";
				RectTransform obj = Util.NormalizeRectWithTopLeft((Component)(object)uIPlanetFinderListItem.labelIcon, 16f, 12f);
				obj.pivot = new Vector2(0.5f, 0.5f);
				obj.sizeDelta = new Vector2(24f, 24f);
				((Transform)obj).localScale = new Vector3(0.3f, 0.3f, 1f);
				((Graphic)uIPlanetFinderListItem.labelIcon).material = null;
				Transform obj2 = ((Component)UIRoot.instance.uiGame.stationWindow.storageUIPrefab).transform.Find("storage-icon-empty/white");
				object obj3;
				if (obj2 == null)
				{
					obj3 = null;
				}
				else
				{
					Image component = ((Component)obj2).GetComponent<Image>();
					obj3 = ((component != null) ? component.sprite : null);
				}
				circleSprite = (Sprite)obj3;
				uIPlanetFinderListItem.labelIcon.sprite = circleSprite;
				((Behaviour)uIPlanetFinderListItem.labelIcon).enabled = true;
			}
			uIPlanetFinderListItem.iconHide = val3.iconHide;
			uIPlanetFinderListItem.iconButton = val3.iconButton;
			Object.Destroy((Object)(object)val3);
			Util.NormalizeRectWithTopLeft((Component)(object)uIPlanetFinderListItem, 0f, 0f);
			return uIPlanetFinderListItem;
		}

		private void Start()
		{
			locateBtn.onClick += OnLocateButtonClick;
			((Component)locateBtn).gameObject.SetActive(false);
		}

		public void SetUpDisplayName()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (starData != null)
			{
				planetName = starData.displayName + distanceStr;
			}
			else
			{
				if (planetData == null)
				{
					return;
				}
				string text = "";
				if (PLFN.showPrefix.Value)
				{
					if ((int)planetData.type == 5)
					{
						text += PLFN.gasGiantPrefix.Value;
					}
					if ((planetData.singularity & 1) != 0)
					{
						text += PLFN.tidalLockedPrefix.Value;
					}
					if (!string.IsNullOrEmpty(text))
					{
						text += " ";
					}
				}
				planetName = text + planetData.displayName + distanceStr;
			}
		}

		public void SetUpPlanetColor()
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Invalid comparison between Unknown and I4
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Invalid comparison between Unknown and I4
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			if (planetData != null)
			{
				ThemeProto val = ((ProtoSet<ThemeProto>)(object)LDB.themes).Select(planetData.theme);
				if (val != null && val.thumbMat != null)
				{
					Color color = val.thumbMat[planetData.style % val.thumbMat.Length].GetColor("_Color");
					if (color.a < 0.5f)
					{
						color.a = 0.5f;
					}
					float num = Mathf.Max(new float[3] { color.r, color.g, color.b });
					if (num > 0.6f)
					{
						color.a = 1.6f - num;
					}
					color.a /= 1.4f;
					planetColor = color;
				}
			}
			else if (starData != null)
			{
				UIVirtualStarmap starmap = UIRoot.instance.galaxySelect.starmap;
				planetColor = starmap.starColors.Evaluate(starData.color);
				if ((int)starData.type == 3)
				{
					planetColor = starmap.neutronStarColor;
				}
				else if ((int)starData.type == 2)
				{
					planetColor = starmap.whiteDwarfColor;
				}
				else if ((int)starData.type == 4)
				{
					planetColor = starmap.blackholeColor;
				}
				planetColor.a = 0.8f;
			}
			else
			{
				planetColor = new Color(1f, 1f, 1f, 0.6f);
			}
		}

		public void Init(in PlanetListData d, UIPlanetFinderWindow window_)
		{
			//IL_0068: 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)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			listData = d;
			firstRefleshed = false;
			window = window_;
			distanceStr = d.distanceStr;
			itemId = d.itemId;
			planetData = d.planetData;
			starData = d.starData;
			SetUpDisplayName();
			SetUpPlanetColor();
			labelIcon.sprite = null;
			((Graphic)valueText).color = valueTextNormalColor;
			int num = 0;
			if (planetData != null)
			{
				num = planetData.id;
			}
			else if (starData != null)
			{
				num = starData.id;
			}
			if (num > 0 && PLFN.aDSPStarMapMemoIntg.canGetSignalIconId && PLFN.integrationWithDSPStarMapMemo.Value)
			{
				int signalIconId = PLFN.aDSPStarMapMemoIntg.GetSignalIconId(num);
				if (signalIconId != 0)
				{
					labelIcon.sprite = LDB.signals.IconSprite(signalIconId);
					((Transform)((Graphic)labelIcon).rectTransform).localScale = Vector3.one;
					((Graphic)labelIcon).color = Color.white;
				}
			}
			if ((Object)(object)labelIcon.sprite == (Object)null)
			{
				((Graphic)labelIcon).color = planetColor;
				labelIcon.sprite = circleSprite;
				((Transform)((Graphic)labelIcon).rectTransform).localScale = new Vector3(0.3f, 0.3f, 1f);
			}
		}

		private void OnLocateButtonClick(int obj)
		{
			if (planetData != null)
			{
				PLFN.LocatePlanet(planetData.id);
			}
			else if (starData != null)
			{
				PLFN.LocatePlanet(0, starData.id);
			}
		}

		public long TargetItemAmount()
		{
			long result = 0L;
			if (planetData != null)
			{
				return TargetItemAmountForPlanet(listData);
			}
			if (starData != null)
			{
				return TargetItemAmountForStar(listData);
			}
			return result;
		}

		public long TargetItemAmountForStar(PlanetListData ld)
		{
			long num = 0L;
			if (ld.starData != null)
			{
				if (itemId > veinCount)
				{
					return 0L;
				}
				foreach (PlanetListData planet in ld.planetList)
				{
					num += TargetItemAmountForPlanet(planet);
				}
			}
			return num;
		}

		public long TargetItemAmountForPlanet(PlanetListData ld)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			PlanetData val = ld.planetData;
			long result = 0L;
			if (val != null)
			{
				if ((int)val.type == 5)
				{
					return 0L;
				}
				if (val.waterItemId >= 1000 && val.waterItemId == itemId)
				{
					return 0L;
				}
				if (itemId <= veinCount)
				{
					return ld.ItemCount(itemId);
				}
			}
			return result;
		}

		public int TargetItemAmountSketch()
		{
			if (planetData != null)
			{
				return TargetItemAmountSketchForPlanet(listData);
			}
			if (starData != null)
			{
				return TargetItemAmountSketchForStar(listData);
			}
			return 0;
		}

		public int TargetItemAmountSketchForStar(PlanetListData ld)
		{
			int num = 0;
			if (ld.starData != null)
			{
				if (itemId > veinCount)
				{
					return 0;
				}
				foreach (PlanetListData planet in ld.planetList)
				{
					num += TargetItemAmountSketchForPlanet(planet);
				}
			}
			return num;
		}

		public int TargetItemAmountSketchForPlanet(PlanetListData ld)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			PlanetData val = ld.planetData;
			int result = 0;
			if (val != null)
			{
				if ((int)val.type == 5)
				{
					return 0;
				}
				if (val.waterItemId >= 1000 && val.waterItemId == itemId)
				{
					return 0;
				}
				if (itemId <= veinCount)
				{
					return ld.ItemCountSketch(itemId);
				}
			}
			return result;
		}

		public void Update()
		{
			if ((planetData != null || starData != null) && (Time.frameCount % 30 == 0 || window.needsReflesh))
			{
				RefreshValues();
			}
		}

		public void RefreshValues()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (!baseObj.activeSelf)
			{
				return;
			}
			int num = _itemId;
			((Graphic)valueText).color = valueTextNormalColor;
			itemId = window.targetItemId;
			if (itemId != 0)
			{
				if (!GameMain.data.gameDesc.isInfiniteResource)
				{
					long num2 = TargetItemAmount();
					if (num2 > 0)
					{
						if (itemId == 7)
						{
							double num3 = (double)num2 * (double)VeinData.oilSpeedMultiplier;
							StringBuilderUtility.WritePositiveFloat(sb, 0, 8, (float)num3, 2, ' ');
						}
						else if (num2 < 1000000000)
						{
							StringBuilderUtility.WriteCommaULong(sb, 0, 16, (ulong)num2, 1, ' ');
						}
						else
						{
							StringBuilderUtility.WriteKMG(sb, 15, num2, false);
						}
						string text = sb.ToString();
						if (firstRefleshed && num == _itemId)
						{
							if (text != valueText.text)
							{
								valueText.text = text;
								((Graphic)valueText).color = valueTextMiningColor;
							}
						}
						else
						{
							valueText.text = text;
						}
					}
					else
					{
						valueText.text = "";
					}
				}
				int num4 = TargetItemAmountSketch();
				if (num4 > 0)
				{
					valueSketchText.text = "(" + num4 + ")";
				}
				else
				{
					valueSketchText.text = "";
				}
			}
			else if (PLFN.showPowerState.Value && planetData?.factory?.powerSystem != null)
			{
				valueText.text = PowerState(out var networkCount);
				if (networkCount > 1)
				{
					valueSketchText.text = "(" + networkCount + ")";
				}
				else
				{
					valueSketchText.text = "";
				}
			}
			else
			{
				valueText.text = "";
				valueSketchText.text = "";
			}
			firstRefleshed = true;
		}

		public string PowerState(out int networkCount)
		{
			string result = "";
			networkCount = 0;
			if (planetData == null)
			{
				return result;
			}
			long num = 0L;
			long num2 = 0L;
			long num3 = 0L;
			PowerSystem powerSystem = planetData.factory.powerSystem;
			for (int i = 1; i < powerSystem.netCursor; i++)
			{
				PowerNetwork val = powerSystem.netPool[i];
				if (val != null && val.id == i)
				{
					networkCount++;
					num += val.energyCapacity;
					num2 += val.energyRequired;
					if (val.energyExchanged < 0)
					{
						num3 -= val.energyExchanged;
					}
				}
			}
			if (num > 0 || num3 > 0)
			{
				StringBuilderUtility.WriteKMG(window.sbWatt, 8, num2 * 60, false);
				result = window.sbWatt.ToString();
				StringBuilderUtility.WriteKMG(window.sbWatt, 8, num * 60, false);
				result = result + " / " + window.sbWatt.ToString().Trim();
				if (num3 > 0)
				{
					StringBuilderUtility.WriteKMG(window.sbWatt, 8, num3 * 60, false);
					result = result + " + " + window.sbWatt.ToString().Trim();
				}
				double num4 = (double)num2 / (double)(num + num3);
				if (num4 > 0.8999999761581421)
				{
					result = result + " (" + num4.ToString("P1") + ")";
					if (num3 <= 0)
					{
						result = ((!(num4 > 0.9900000095367432)) ? ("<color=#DB883E85>" + result + "</color>") : ("<color=#FF404D99>" + result + "</color>"));
					}
				}
			}
			else
			{
				result = "--";
			}
			return result;
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (!disableUIAction && (int)eventData.button == 1)
			{
				window.ShowMenu(this);
			}
		}

		public void OnPointerEnter(PointerEventData _eventData)
		{
			if (!disableUIAction)
			{
				((Component)locateBtn).gameObject.SetActive(true);
			}
		}

		public void OnPointerExit(PointerEventData _eventData)
		{
			if (!disableUIAction)
			{
				((Component)locateBtn).gameObject.SetActive(false);
			}
		}

		public void LockAppearance()
		{
			Button component = ((Component)this).GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
		}

		public void UnlockAppearance()
		{
			Button component = ((Component)this).GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = true;
			}
		}
	}
	public enum Scope
	{
		None,
		CurrentStar,
		Planet,
		HasFactory,
		Fav,
		Recent,
		Gas,
		System
	}
	public class PlanetListData
	{
		public int distanceForSort;

		public string distanceStr;

		public PlanetData planetData;

		public StarData starData;

		public List<PlanetListData> planetList;

		public int itemId;

		public long amount;

		public bool shouldShow;

		public VeinGroup[] cachedVeinGroups;

		public static int CalculatedOrLoadedCount(List<PlanetListData> list)
		{
			int num = 0;
			foreach (PlanetListData item in list)
			{
				if (item.IsCalculatedOrLoaded())
				{
					num++;
				}
			}
			return num;
		}

		public bool IsCalculatedOrLoaded()
		{
			if (!planetData.calculated)
			{
				return cachedVeinGroups != null;
			}
			return true;
		}

		public VeinGroup[] VeinGroups()
		{
			if (!planetData.calculated)
			{
				return cachedVeinGroups;
			}
			return planetData.runtimeVeinGroups;
		}

		public bool IsContainItem(int itemId)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			VeinGroup[] array = VeinGroups();
			if (array == null)
			{
				return false;
			}
			for (int i = 1; i < array.Length; i++)
			{
				if ((int)array[i].type == itemId && array[i].amount > 0)
				{
					return true;
				}
			}
			return false;
		}

		public long ItemCount(int itemId)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			long num = 0L;
			VeinGroup[] array = VeinGroups();
			if (array == null)
			{
				return 0L;
			}
			for (int i = 1; i < array.Length; i++)
			{
				if ((int)array[i].type == itemId)
				{
					num += array[i].amount;
				}
			}
			return num;
		}

		public int ItemCountSketch(int itemId)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			int num = 0;
			VeinGroup[] array = VeinGroups();
			if (array == null)
			{
				return 0;
			}
			for (int i = 1; i < array.Length; i++)
			{
				if ((int)array[i].type == itemId)
				{
					num += array[i].count;
				}
			}
			return num;
		}
	}
	public class UIPlanetFinderWindow : ManualBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, MyWindow
	{
		public enum EMenuCommand
		{
			Close,
			OpenStarmap,
			Fav,
			OpenLSTM,
			SetCruiseAssist
		}

		public RectTransform windowTrans;

		public RectTransform contentTrans;

		public bool needsReflesh;

		public Scope scope;

		public List<UIButton> scopeButtons;

		public int targetItemId;

		public UIItemSelection itemSelection;

		public MyListView planetListView;

		public Text countText;

		public InputField searchField;

		public string searchString;

		public UIButton searchFieldClearBtn;

		public StringBuilder sb;

		public StringBuilder sbOil;

		public StringBuilder sbWatt;

		internal bool _eventLock;

		public bool isPointEnter;

		private bool focusPointEnter;

		public List<PlanetListData> _allPlanetList = new List<PlanetListData>(800);

		public List<PlanetListData> _allStarList = new List<PlanetListData>(80);

		public List<PlanetListData> _planetList = new List<PlanetListData>(800);

		private static Thread _planetCalculateThread;

		public bool _stopThread;

		private static UIPlanetFinderWindow _instance;

		public const int veinCount = 15;

		public GameObject popupMenuBase;

		public UIPlanetFinderListItem popupMenuListItem;

		public UIPlanetFinderListItem menuTarget;

		public UIButton favBtn;

		public const float popupMenuTopMargin = 30f;

		private static void PlanetCalculateThreadMain()
		{
			long seedKey = GameMain.data.gameDesc.seedKey64;
			int num = _instance._allPlanetList?.Count ?? 0;
			Thread.Sleep(3000);
			MyWindowCtl.SetTitle((ManualBehaviour)(object)_instance, "Planet Finder");
			for (int i = 0; i < num; i++)
			{
				if (_instance._stopThread || num != _instance._allPlanetList.Count || seedKey != GameMain.data.gameDesc.seedKey64)
				{
					return;
				}
				PlanetListData planetListData = _instance._allPlanetList[i];
				MyWindowCtl.SetTitle((ManualBehaviour)(object)_instance, "Init... (" + PlanetListData.CalculatedOrLoadedCount(_instance._allPlanetList) + "/" + num + ")");
				if (!planetListData.IsCalculatedOrLoaded())
				{
					bool flag = true;
					if (planetListData.planetData.calculating)
					{
						flag = false;
					}
					else
					{
						if (_instance._stopThread)
						{
							return;
						}
						PlanetModelingManager.RequestCalcPlanet(planetListData.planetData);
					}
					do
					{
						Thread.Sleep(100);
						if (_instance._stopThread)
						{
							return;
						}
					}
					while (!planetListData.planetData.calculated);
					VeinGroup[] runtimeVeinGroups = planetListData.planetData.runtimeVeinGroups;
					int num2 = runtimeVeinGroups.Length;
					int num3 = ((num2 < 1) ? 1 : num2);
					planetListData.cachedVeinGroups = (VeinGroup[])(object)new VeinGroup[num3];
					Array.Copy(runtimeVeinGroups, planetListData.cachedVeinGroups, num2);
					((VeinGroup)(ref planetListData.cachedVeinGroups[0])).SetNull();
					if (flag)
					{
						int num4 = GameMain.localStar?.id ?? 0;
						if (planetListData.planetData.id / 100 != num4)
						{
							planetListData.planetData.data.Free();
							planetListData.planetData.data = null;
							planetListData.planetData.modData = null;
							planetListData.planetData.aux = null;
							planetListData.planetData.calculated = false;
						}
					}
				}
				else
				{
					VeinGroup[] runtimeVeinGroups2 = planetListData.planetData.runtimeVeinGroups;
					int num5 = runtimeVeinGroups2.Length;
					int num6 = ((num5 < 1) ? 1 : num5);
					planetListData.cachedVeinGroups = (VeinGroup[])(object)new VeinGroup[num6];
					Array.Copy(runtimeVeinGroups2, planetListData.cachedVeinGroups, num5);
					((VeinGroup)(ref planetListData.cachedVeinGroups[0])).SetNull();
				}
			}
			MyWindowCtl.SetTitle((ManualBehaviour)(object)_instance, "Planet Finder");
			PLFN.Log("loading vein data completed");
		}

		public static UIPlanetFinderWindow CreateInstance()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				return _instance;
			}
			_instance = MyWindowCtl.CreateWindow<UIPlanetFinderWindow>("PlanetFinderWindow", "Planet Finder");
			return _instance;
		}

		public void BeginGame()
		{
			if (DSPGame.IsMenuDemo)
			{
				return;
			}
			_eventLock = true;
			GalaxyData galaxy = GameMain.galaxy;
			_allPlanetList.Clear();
			_allStarList.Clear();
			_planetList.Clear();
			for (int i = 0; i < galaxy.starCount; i++)
			{
				StarData val = galaxy.stars[i];
				PlanetListData planetListData = new PlanetListData
				{
					planetData = null,
					starData = val,
					distanceForSort = 0,
					distanceStr = null,
					itemId = targetItemId,
					shouldShow = false,
					planetList = new List<PlanetListData>()
				};
				_allStarList.Add(planetListData);
				for (int j = 0; j < val.planetCount; j++)
				{
					PlanetData planetData = val.planets[j];
					PlanetListData item = new PlanetListData
					{
						planetData = planetData,
						starData = null,
						distanceForSort = 0,
						distanceStr = null,
						itemId = targetItemId,
						shouldShow = false
					};
					_allPlanetList.Add(item);
					planetListData.planetList.Add(item);
				}
			}
			searchField.text = "";
			searchString = null;
			_stopThread = false;
			_planetCalculateThread = new Thread(PlanetCalculateThreadMain);
			_planetCalculateThread.Start();
			_eventLock = false;
		}

		public void EndGame()
		{
			if (_planetCalculateThread != null)
			{
				_stopThread = true;
				_planetCalculateThread.Abort();
				_planetCalculateThread = null;
				Thread.Sleep(1600);
			}
			MyWindowCtl.SetTitle((ManualBehaviour)(object)this, "Planet Finder");
		}

		public void SetUpAndOpen(int _itemId = 0)
		{
			SetUpData();
			MyWindowCtl.OpenWindow((ManualBehaviour)(object)this);
		}

		public bool isFunctionWindow()
		{
			return false;
		}

		public Vector2 WindowSize()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Round(PLFN.mainWindowSize.Value);
			if (num < 4f)
			{
				num = 4f;
			}
			if (num > 16f)
			{
				num = 16f;
			}
			return new Vector2(640f, 174f + 28f * num);
		}

		private void PopulateItem(MonoBehaviour item, int rowIndex)
		{
			UIPlanetFinderListItem obj = item as UIPlanetFinderListItem;
			PlanetListData d = _planetList[rowIndex];
			obj.Init(in d, this);
			obj.RefreshValues();
		}

		public override void _OnCreate()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Expected O, but got Unknown
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			_eventLock = true;
			windowTrans = MyWindowCtl.GetRectTransform((ManualBehaviour)(object)this);
			windowTrans.sizeDelta = WindowSize();
			GameObject val = new GameObject("content");
			contentTrans = val.AddComponent<RectTransform>();
			Util.NormalizeRectWithMargin((Component)(object)contentTrans, 60f, 28f, 20f, 28f, (Transform)(object)windowTrans);
			Image val2 = Util.CreateGameObject<Image>("list-bg", 100f, 100f);
			((Graphic)val2).color = new Color(0f, 0f, 0f, 0.56f);
			Util.NormalizeRectWithMargin((Component)(object)val2, 70f, 0f, 20f, 16f, (Transform)(object)contentTrans);
			planetListView = MyListView.CreateListView((MonoBehaviour)(object)UIPlanetFinderListItem.CreateListViewPrefab(), PopulateItem, "list-view");
			Util.NormalizeRectWithMargin((Component)(object)((Component)planetListView).transform, 0f, 0f, 0f, 0f, ((Component)val2).transform);
			planetListView.m_ScrollRect.scrollSensitivity = 28f;
			float scopex_ = 4f;
			scopeButtons = new List<UIButton>(8);
			scopeButtons.Add(AddScope("Sys", 7));
			scopeButtons.Add(AddScope("All Planet", 2));
			scopeButtons.Add(AddScope("Current Star", 1));
			scopeButtons.Add(AddScope("Has Factory", 3));
			scopeButtons.Add(AddScope("★", 4));
			scopeButtons.Add(AddScope("Recent", 5));
			scope = Scope.Planet;
			foreach (UIButton scopeButton in scopeButtons)
			{
				scopeButton.highlighted = scopeButton.data == (int)scope;
			}
			itemSelection = UIItemSelection.CreateInstance();
			RectTransform val3 = Util.NormalizeRectWithTopLeft((Component)(object)itemSelection, 0f, 28f, (Transform)(object)contentTrans);
			itemSelection.planetFinderWindow = this;
			countText = Util.CreateText("", 14, "result-count");
			Util.NormalizeRectWithBottomLeft((Component)(object)countText, 2f, 0f, (Transform)(object)contentTrans);
			string text = "                ";
			sb = new StringBuilder(text, text.Length + 2);
			text = "         /s";
			sbOil = new StringBuilder(text, text.Length + 2);
			sbWatt = new StringBuilder("         W", 12);
			Sprite sprite = null;
			UIButton[] buildingWarnButtons = UIRoot.instance.optionWindow.buildingWarnButtons;
			if (buildingWarnButtons.Length >= 4)
			{
				Transform obj = ((Component)buildingWarnButtons[3]).transform.Find("image");
				Image val4 = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
				if ((Object)(object)val4 != (Object)null)
				{
					sprite = val4.sprite;
				}
			}
			UIButton val5 = Util.MakeIconButtonC(sprite, 32f);
			((UnityEvent)val5.button.onClick).AddListener(new UnityAction(OnConfigButtonClick));
			val3 = Util.NormalizeRectWithTopLeft((Component)(object)val5, 158f, 20f, (Transform)(object)windowTrans);
			((Object)((Component)val5).gameObject).name = "config-button";
			((Component)val5).gameObject.SetActive(true);
			((Graphic)((Component)val5).gameObject.GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0.17f);
			if (val5.transitions.Length != 0)
			{
				val5.transitions[0].mouseoverColor = new Color(1f, 1f, 1f, 0.67f);
				val5.transitions[0].normalColor = new Color(1f, 1f, 1f, 0.17f);
				val5.transitions[0].pressedColor = new Color(1f, 1f, 1f, 0.5f);
			}
			UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;
			searchField = Object.Instantiate<InputField>(stationWindow.nameInput);
			((Object)((Com