Decompiled source of DSPStationInfo v0.4.9

DSPStationInfo.dll

Decompiled 4 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DspFontPatcher")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DspFontPatcher")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("81DF3045-8007-4F6A-AAF6-903139D85B6C")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
namespace DSPStationInfo;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Appun.DSP.plugin.StationInfo", "DSPStationInfo", "0.4.9")]
[BepInProcess("DSPGAME.exe")]
public class Main : BaseUnityPlugin
{
	public struct Station
	{
		public Vector2 UIpos;

		public int id;

		public float dist;

		public int maxStorage;

		public float num;
	}

	public static ConfigEntry<bool> ShowStationInfo;

	public static ConfigEntry<int> maxInfo;

	public static ConfigEntry<bool> HideEmptySlot;

	public static bool gigaStationEnable = false;

	public static int maxKinds = 12;

	public static List<Station> stationList = new List<Station>();

	public void Start()
	{
		LogManager.Logger = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		ShowStationInfo = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowStationInfo", true, "Show Station Information");
		maxInfo = ((BaseUnityPlugin)this).Config.Bind<int>("General", "maxInfo", 20, "Maximum number of station information to be displayed");
		HideEmptySlot = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HideEmptySlot", false, "Hide Empty Item Slot");
		UI.create();
	}

	public static void OnSignButtonClick()
	{
		ShowStationInfo.Value = !ShowStationInfo.Value;
		UI.signButton.GetComponent<UIButton>().highlighted = ShowStationInfo.Value;
		if (!ShowStationInfo.Value)
		{
			for (int i = 0; i < maxInfo.Value; i++)
			{
				UI.tipBox[i].SetActive(false);
			}
		}
	}

	public void Update()
	{
		//IL_002a: 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: Invalid comparison between Unknown and I4
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Invalid comparison between Unknown and I4
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: 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_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_045a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: 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_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0583: Unknown result type (might be due to invalid IL or missing references)
		//IL_0566: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0716: Unknown result type (might be due to invalid IL or missing references)
		//IL_07bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_078b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0792: Unknown result type (might be due to invalid IL or missing references)
		UIStorageWindow storageWindow = UIRoot.instance.uiGame.storageWindow;
		if (!ShowStationInfo.Value)
		{
			return;
		}
		if ((int)UIGame.viewMode != 0 && (int)UIGame.viewMode != 3 && (int)UIGame.viewMode != 1)
		{
			UI.stationTip.SetActive(false);
		}
		else
		{
			if (GameMain.data == null)
			{
				return;
			}
			PlanetData localPlanet = GameMain.data.localPlanet;
			if (localPlanet == null || localPlanet.factory == null)
			{
				return;
			}
			UI.stationTip.SetActive(true);
			Vector3 localPosition = ((Component)GameCamera.main).transform.localPosition;
			Vector3 forward = ((Component)GameCamera.main).transform.forward;
			StationComponent[] stationPool = localPlanet.factory.transport.stationPool;
			float realRadius = localPlanet.realRadius;
			if (stationPool.Length == 0)
			{
				return;
			}
			Vector2 val4 = default(Vector2);
			RCHCPU val5 = default(RCHCPU);
			for (int i = 0; i < stationPool.Length; i++)
			{
				StationComponent val = stationPool[i];
				if (val == null || stationPool[i].id == 0)
				{
					continue;
				}
				Vector3 val2;
				int num;
				if (val.isVeinCollector)
				{
					val2 = ((Vector3)(ref localPlanet.factory.entityPool[val.entityId].pos)).normalized * (realRadius + 10f);
					num = 1;
				}
				else if (val.isCollector)
				{
					val2 = ((Vector3)(ref localPlanet.factory.entityPool[val.entityId].pos)).normalized * (realRadius + 35f);
					num = 2;
				}
				else
				{
					if (HideEmptySlot.Value)
					{
						int num2 = 0;
						for (int j = 0; j < val.storage.Length; j++)
						{
							if (val.storage[j].itemId != 0)
							{
								num2++;
							}
						}
						num = num2;
					}
					else
					{
						num = val.storage.Length;
					}
					val2 = ((Vector3)(ref localPlanet.factory.entityPool[val.entityId].pos)).normalized * (realRadius + 14f + (float)num * 1.4f);
				}
				Vector3 val3 = val2 - localPosition;
				float magnitude = ((Vector3)(ref val3)).magnitude;
				float num3 = Vector3.Dot(forward, val3);
				bool flag = UIRoot.ScreenPointIntoRect(GameCamera.main.WorldToScreenPoint(val2), UI.stationTip.GetComponent<RectTransform>(), ref val4);
				if (Mathf.Abs(val4.x) > 8000f)
				{
					flag = false;
				}
				if (Mathf.Abs(val4.y) > 8000f)
				{
					flag = false;
				}
				if (Phys.RayCastSphere(localPosition, val3 / magnitude, magnitude, Vector3.zero, realRadius, ref val5))
				{
					flag = false;
				}
				if (flag)
				{
					Station item = default(Station);
					item.UIpos.x = Mathf.Round(val4.x);
					item.UIpos.y = Mathf.Round(val4.y);
					item.id = val.id;
					item.dist = magnitude;
					item.maxStorage = num;
					item.num = num3;
					stationList.Add(item);
				}
			}
			stationList.Sort((Station a, Station b) => a.dist.CompareTo(b.dist));
			if (stationList.Count > maxInfo.Value)
			{
				stationList.RemoveRange(maxInfo.Value, stationList.Count - maxInfo.Value);
			}
			for (int k = 0; k < stationList.Count; k++)
			{
				int index = stationList.Count - k - 1;
				StationComponent val6 = stationPool[stationList[index].id];
				if (val6.storage == null)
				{
					continue;
				}
				UI.tipBox[k].GetComponent<RectTransform>().anchoredPosition = stationList[index].UIpos;
				int num4 = 0;
				for (int l = 0; l < val6.storage.Length; l++)
				{
					if (val6.storage[l].itemId != 0)
					{
						UI.tipIcon[k, num4].sprite = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val6.storage[l].itemId).iconSprite;
						((Component)UI.tipIcon[k, num4]).gameObject.SetActive(true);
						UI.tipCounter[k, num4].text = val6.storage[l].count.ToString("#,##0");
						if (val6.storage[l].count * 10 < val6.storage[l].max)
						{
							((Graphic)UI.tipCounter[k, num4]).color = new Color(1f, 0.45f, 0.2f, 1f);
						}
						else
						{
							((Graphic)UI.tipCounter[k, num4]).color = Color.white;
						}
						((Component)UI.tipCounter[k, num4]).gameObject.SetActive(true);
						num4++;
					}
					else if (!HideEmptySlot.Value)
					{
						((Component)UI.tipIcon[k, l]).gameObject.SetActive(false);
						UI.tipCounter[k, l].text = "-----------";
						((Graphic)UI.tipCounter[k, l]).color = Color.white;
						((Component)UI.tipCounter[k, l]).gameObject.SetActive(true);
						num4++;
					}
					UI.tipBox[k].SetActive(true);
				}
				for (int m = num4; m < maxKinds; m++)
				{
					((Component)UI.tipIcon[k, m]).gameObject.SetActive(false);
					((Component)UI.tipCounter[k, m]).gameObject.SetActive(false);
				}
				UI.tipBox[k].GetComponent<RectTransform>().sizeDelta = new Vector2(100f, (float)(num4 * 30 + 10));
				if (stationList[index].dist < 50f)
				{
					UI.tipBox[k].transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
				}
				else if (stationList[index].dist < 250f)
				{
					float num5 = (float)(1.75 - (double)stationList[index].dist * 0.005);
					UI.tipBox[k].transform.localScale = new Vector3(1f, 1f, 1f) * num5;
				}
				else
				{
					UI.tipBox[k].transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
				}
			}
			for (int n = stationList.Count; n < maxInfo.Value; n++)
			{
				UI.tipBox[n].SetActive(false);
			}
			stationList.Clear();
		}
	}
}
public class LogManager
{
	public static ManualLogSource Logger;
}
[HarmonyPatch]
internal class Patches
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIGameMenu), "OnButton1Click")]
	public static void UIGameMenu_OnButton1Click_PostPatch()
	{
		((Component)UI.signButton.transform.Find("icon")).GetComponent<Image>().sprite = ((ProtoSet<TechProto>)(object)LDB.techs).Select(1604).iconSprite;
		if (Main.ShowStationInfo.Value)
		{
			UI.signButton.GetComponent<UIButton>().highlighted = true;
		}
		else
		{
			UI.signButton.GetComponent<UIButton>().highlighted = false;
		}
	}
}
internal class UI : MonoBehaviour
{
	public static GameObject[] tipBox = (GameObject[])(object)new GameObject[Main.maxInfo.Value];

	public static Text[,] tipCounter = new Text[Main.maxInfo.Value, Main.maxKinds];

	public static Image[,] tipIcon = new Image[Main.maxInfo.Value, Main.maxKinds];

	public static GameObject stationTip;

	public static GameObject tipPrefab;

	public static GameObject signButton;

	public static void create()
	{
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		stationTip = Object.Instantiate<GameObject>(GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs/Vein Marks"), GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs").transform);
		((Object)stationTip).name = "stationTip";
		Object.Destroy((Object)(object)stationTip.GetComponent<UIVeinDetail>());
		signButton = Object.Instantiate<GameObject>(GameObject.Find("UI Root/Overlay Canvas/In Game/Game Menu/detail-func-group/dfunc-1"), GameObject.Find("UI Root/Overlay Canvas/In Game/Game Menu/detail-func-group").transform);
		((Object)signButton).name = "signButton";
		signButton.transform.localPosition = GameObject.Find("UI Root/Overlay Canvas/In Game/Game Menu/detail-func-group/dfunc-8").transform.localPosition;
		signButton.GetComponent<UIButton>().tips.tipTitle = Localization.Translate("Station Contents");
		signButton.GetComponent<UIButton>().tips.tipText = Localization.Translate("Click to turn ON / OFF real-time contents of stations");
		((UnityEvent)signButton.GetComponent<UIButton>().button.onClick).AddListener(new UnityAction(Main.OnSignButtonClick));
		tipPrefab = Object.Instantiate<GameObject>(GameObject.Find("UI Root/Overlay Canvas/In Game/Scene UIs/Vein Marks/vein-tip-prefab"), stationTip.transform);
		((Object)tipPrefab).name = "tipPrefab";
		tipPrefab.GetComponent<Image>().sprite = GameObject.Find("UI Root/Overlay Canvas/In Game/Windows/Key Tips/tip-prefab").GetComponent<Image>().sprite;
		((Graphic)tipPrefab.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.8f);
		tipPrefab.GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 160f);
		((Behaviour)tipPrefab.GetComponent<Image>()).enabled = true;
		tipPrefab.transform.localPosition = new Vector3(200f, 800f, 0f);
		tipPrefab.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f);
		Object.Destroy((Object)(object)tipPrefab.GetComponent<UIVeinDetailNode>());
		tipPrefab.SetActive(false);
		for (int i = 0; i < Main.maxKinds; i++)
		{
			InstantiateTip(i);
		}
		((Component)tipPrefab.transform.Find("info-text")).gameObject.SetActive(false);
		((Component)tipPrefab.transform.Find("icon")).gameObject.SetActive(false);
		for (int j = 0; j < Main.maxInfo.Value; j++)
		{
			tipBox[j] = Object.Instantiate<GameObject>(tipPrefab, stationTip.transform);
			for (int k = 0; k < Main.maxKinds; k++)
			{
				tipCounter[j, k] = ((Component)tipBox[j].transform.Find("countText" + k)).GetComponent<Text>();
				tipIcon[j, k] = ((Component)tipBox[j].transform.Find("icon" + k)).GetComponent<Image>();
			}
		}
	}

	public static void InstantiateTip(int i)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = GameObject.Find("UI Root/Overlay Canvas/In Game/Planet & Star Details/planet-detail-ui/detail_group/res-group/res-entry/value-text").gameObject;
		GameObject val = Object.Instantiate<GameObject>(((Component)tipPrefab.transform.Find("info-text")).gameObject, new Vector3(0f, 0f, 0f), Quaternion.identity, tipPrefab.transform);
		((Object)val).name = "countText" + i;
		val.GetComponent<Text>().fontSize = 20;
		val.GetComponent<Text>().font = gameObject.GetComponent<Text>().font;
		val.GetComponent<Text>().text = "99999";
		val.GetComponent<Text>().alignment = (TextAnchor)5;
		val.GetComponent<RectTransform>().sizeDelta = new Vector2(95f, 30f);
		val.GetComponent<RectTransform>().anchorMax = new Vector2(0f, 1f);
		val.GetComponent<RectTransform>().anchorMin = new Vector2(0f, 1f);
		val.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
		val.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(0f, (float)(-5 - 30 * i), 0f);
		Object.Destroy((Object)(object)val.GetComponent<Shadow>());
		GameObject val2 = Object.Instantiate<GameObject>(((Component)tipPrefab.transform.Find("icon")).gameObject, new Vector3(0f, 0f, 0f), Quaternion.identity, tipPrefab.transform);
		((Object)val2).name = "icon" + i;
		val2.GetComponent<RectTransform>().anchorMax = new Vector2(0f, 1f);
		val2.GetComponent<RectTransform>().anchorMin = new Vector2(0f, 1f);
		val2.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
		val2.GetComponent<RectTransform>().anchoredPosition3D = new Vector3(5f, (float)(-5 - 30 * i), 0f);
	}
}