Decompiled source of BetterOrder v1.0.3

BepInEx/plugins/FateArth/FateArth.BetterDockOrderPlugin.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization.Components;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FateArth.BetterDockOrderPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("更好的订购")]
[assembly: AssemblyTitle("FateArth.BetterDockOrderPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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]
	[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 BetterDockOrderPlugin
{
	[HarmonyPatch]
	public class BetterDockOrderPatch : MonoBehaviour
	{
		private struct Data
		{
			public long ItemId;

			public string ItemName;

			public int TotalAmount;
		}

		private static Dictionary<string, Data> itemList = new Dictionary<string, Data>();

		private static int listCount;

		private static List<int> indexList = new List<int>();

		[HarmonyPatch(typeof(UIManager), "UpdateDockOrdersPanel")]
		[HarmonyPrefix]
		private static void Prefix1(UIManager __instance)
		{
			IEnumerable<Item> source = from x in Object.FindObjectsOfType<Item>()
				where x.itemSO is ProductSO
				select x;
			itemList.Clear();
			if (source.Count() <= 0)
			{
				return;
			}
			foreach (Data item in (from item in source
				orderby item.itemSO.itemName
				group item by item.itemSO.id).Select(delegate(IGrouping<long, Item> group)
			{
				Data result = default(Data);
				result.ItemId = group.Key;
				result.ItemName = GameManager.Instance.GetItemById(group.Key).GetLocalizedName();
				result.TotalAmount = group.Sum((Item item) => item.amount.Value);
				return result;
			}))
			{
				itemList.Add(item.ItemName, item);
			}
		}

		[HarmonyPatch(typeof(UIManager), "UpdateDockOrdersPanel")]
		[HarmonyPrefix]
		private static void Prefix2(UIManager __instance)
		{
			listCount = ((Component)__instance.listDockOrders).transform.childCount;
			indexList.Clear();
			for (int i = 0; i < listCount; i++)
			{
				if (((Component)((Component)__instance.listDockOrders).transform.GetChild(i)).gameObject.activeSelf)
				{
					indexList.Add(i);
				}
			}
			for (int num = ((Component)__instance.listDockOrders).transform.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)((Component)__instance.listDockOrders).transform.GetChild(num)).gameObject);
			}
		}

		[HarmonyPatch(typeof(UIManager), "UpdateDockOrdersPanel")]
		[HarmonyPostfix]
		private static void Postfix3(UIManager __instance)
		{
			if (listCount != ((Component)__instance.listDockOrders).transform.childCount)
			{
				return;
			}
			for (int i = 0; i < listCount; i++)
			{
				if (indexList.Contains(i))
				{
					((Component)((Component)__instance.listDockOrders).transform.GetChild(i)).gameObject.SetActive(true);
				}
				else
				{
					((Component)((Component)__instance.listDockOrders).transform.GetChild(i)).gameObject.SetActive(false);
				}
			}
		}

		[HarmonyPatch(typeof(DockOrderTile), "SetData")]
		[HarmonyPostfix]
		private static void Postfix1(DockOrderTile __instance, ProductSO productSO, int amount)
		{
			if (Plugin.configShow.Value && itemList.ContainsKey(((ItemSO)productSO).GetLocalizedName()))
			{
				TextMeshProUGUI textTitle = __instance.textTitle;
				((TMP_Text)textTitle).text = ((TMP_Text)textTitle).text + $" {Plugin.configstring3.Value}{itemList[((ItemSO)productSO).GetLocalizedName()].TotalAmount}";
			}
		}

		[HarmonyPatch(typeof(UIManager), "Awake")]
		[HarmonyPostfix]
		private static void Postfix2()
		{
			UIManager.Instance.panelDockOrders.AddComponent<CreateDockOrderSort>();
		}
	}
	public class CreateDockOrderSort : MonoBehaviour
	{
		public Button allBtn;

		public Button defaultBtn;

		public Button Btn1;

		public Button Btn2;

		public Button Btn3;

		public Button Btn4;

		public Button Btn5;

		public Button Btn6;

		public Button Btn7;

		public Button Btn8;

		public Button Btn9;

		public Button Btn10;

		public Button Btn11;

		public Button Btn12;

		public Button Btn13;

		private Transform content;

		private GameObject buttonListObj;

		private GameObject textObj;

		private Button btnObj;

		private List<Button> btnlist = new List<Button>();

		private List<TextMeshProUGUI> textlist = new List<TextMeshProUGUI>();

		private Transform dockOrderTiles;

		private List<LicenseSO> activeLicenses = new List<LicenseSO>();

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Expected O, but got Unknown
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Expected O, but got Unknown
			dockOrderTiles = ((Component)this).transform.Find("Content/Scroll View/Viewport/Content");
			content = ((Component)this).transform.Find("Content");
			buttonListObj = Object.Instantiate<GameObject>(new GameObject(), content);
			((Object)buttonListObj).name = "ButtonList";
			buttonListObj.AddComponent<VerticalLayoutGroup>();
			buttonListObj.transform.localPosition = new Vector3(-670f, 0f, 0f);
			buttonListObj.GetComponent<RectTransform>().sizeDelta = new Vector2(150f, 600f);
			GameObject val = Object.Instantiate<GameObject>(((Component)((Component)this).transform.Find("Content/ButtonClose")).gameObject, content);
			Object.DestroyImmediate((Object)(object)val.GetComponent<Button>());
			btnObj = val.AddComponent<Button>();
			Object.DestroyImmediate((Object)(object)((Component)((Component)btnObj).transform.Find("Image")).gameObject);
			textObj = Object.Instantiate<GameObject>(((Component)((Component)this).transform.Find("Content/TextTitle")).gameObject, ((Component)btnObj).transform);
			Object.DestroyImmediate((Object)(object)textObj.GetComponent<LocalizeStringEvent>());
			RectTransform component = textObj.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			activeLicenses = GameManager.Instance.licenseDatabase;
			for (int j = 0; j < activeLicenses.Count + 2; j++)
			{
				Button val2 = Object.Instantiate<Button>(btnObj, buttonListObj.transform);
				btnlist.Add(((Component)val2).GetComponent<Button>());
				textlist.Add(((Component)val2).GetComponentInChildren<TextMeshProUGUI>());
			}
			for (int k = 0; k < btnlist.Count; k++)
			{
				switch (k)
				{
				case 0:
					((TMP_Text)textlist[k]).text = Plugin.configstring1.Value;
					((UnityEvent)btnlist[k].onClick).AddListener((UnityAction)delegate
					{
						for (int m = 0; m < dockOrderTiles.childCount; m++)
						{
							((Component)dockOrderTiles.GetChild(m)).gameObject.SetActive(true);
						}
					});
					continue;
				case 1:
					((TMP_Text)textlist[k]).text = Plugin.configstring2.Value;
					((UnityEvent)btnlist[k].onClick).AddListener((UnityAction)delegate
					{
						for (int n = 0; n < dockOrderTiles.childCount; n++)
						{
							((Component)dockOrderTiles.GetChild(n)).gameObject.SetActive(true);
						}
						for (int num = 0; num < activeLicenses.Count; num++)
						{
							LicenseSO licenseSO2 = activeLicenses[num];
							string[] source2 = (from x in GameManager.Instance.itemDatabase.Where((ItemSO x) => x is ProductSO).Cast<ProductSO>().ToList()
								where (Object)(object)x.requiredLicense == (Object)(object)licenseSO2
								select x into obj
								select ((ItemSO)obj).GetLocalizedName()).ToArray();
							for (int num2 = 0; num2 < dockOrderTiles.childCount; num2++)
							{
								if (((Component)dockOrderTiles.GetChild(num2)).gameObject.activeSelf && source2.Contains(((TMP_Text)((Component)dockOrderTiles.GetChild(num2)).GetComponent<DockOrderTile>().textTitle).text.Split(" (")[0]))
								{
									((Component)dockOrderTiles.GetChild(num2)).gameObject.SetActive(false);
								}
							}
						}
					});
					continue;
				}
				((TMP_Text)textlist[k]).text = activeLicenses[k - 2].GetLocalizedName();
				int i1 = k;
				((UnityEvent)btnlist[k].onClick).AddListener((UnityAction)delegate
				{
					LicenseSO licenseSO = activeLicenses[i1 - 2];
					string[] source = (from x in GameManager.Instance.itemDatabase.Where((ItemSO x) => x is ProductSO).Cast<ProductSO>().ToList()
						where (Object)(object)x.requiredLicense == (Object)(object)licenseSO
						select x into obj
						select ((ItemSO)obj).GetLocalizedName()).ToArray();
					for (int l = 0; l < dockOrderTiles.childCount; l++)
					{
						if (source.Contains(((TMP_Text)((Component)dockOrderTiles.GetChild(l)).GetComponent<DockOrderTile>().textTitle).text.Split(" (")[0]))
						{
							((Component)dockOrderTiles.GetChild(l)).gameObject.SetActive(true);
						}
						else
						{
							((Component)dockOrderTiles.GetChild(l)).gameObject.SetActive(false);
						}
					}
				});
			}
			Object.Destroy((Object)(object)((Component)btnObj).gameObject);
		}
	}
	[BepInPlugin("FateArth.BetterDockOrderPlugin", "更好的订购", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static Harmony harmony;

		private ConfigFile configFile;

		public static ConfigEntry<string> configstring1;

		public static ConfigEntry<string> configstring2;

		public static ConfigEntry<string> configstring3;

		public static ConfigEntry<bool> configShow;

		private void Awake()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			configFile = ((BaseUnityPlugin)this).Config;
			int value = configFile.Bind<int>("Settings", "ConfigVersion", 1, "Configuration version").Value;
			if (value < 2)
			{
				UpdateConfig();
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("FateArth.BetterDockOrderPlugin");
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin FateArth.BetterDockOrderPlugin is loaded!");
		}

		private void UpdateConfig()
		{
			configstring1 = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ShowAll", "所有", "Display all ordered products.\n显示所有订购商品");
			configstring2 = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Default", "初始", "\nDisplay default products.\n显示默认商品");
			configstring3 = ((BaseUnityPlugin)this).Config.Bind<string>("General", "RemainingStock", "剩余:", "Prefix for displaying stock quantity in orders.\n订购显示库存数量的前缀");
			configShow = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowRepertory", true, "Should the order page display stock.\n是否订购页面显示库存");
			configFile.Bind<int>("Settings", "ConfigVersion", 2, "Configuration version");
			configFile.Save();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FateArth.BetterDockOrderPlugin";

		public const string PLUGIN_NAME = "更好的订购";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}