Decompiled source of BuildBarTool v1.0.1

BuildBarTool.dll

Decompiled 3 months ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BuildToolOpt;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using RebindBuildBar;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using xiaoye97;
using xiaoye97.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BuildMenuTool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("微软中国")]
[assembly: AssemblyProduct("BuildMenuTool")]
[assembly: AssemblyCopyright("Copyright © 微软中国 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e96ebd1f-e9ee-4d2b-ae96-e464734bac73")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BuildBarTool;

internal class BBTProtos
{
	public static void AddLocalizationProtos()
	{
		LocalizationModule.RegisterTranslation("gmLockedItemText", "Locked  ", "锁定", "Locked  ");
		LocalizationModule.RegisterTranslation("切换快捷键", "CapsLock\n↑ Hotkey Row ↓", "CapsLock\n↑快捷键切换↓", "CapsLock\n↑ Hotkey Row ↓");
	}
}
public static class BuildBarTool
{
	public static bool SetBuildBar(int category, int index, int itemId, bool isTopRow)
	{
		if (category >= 1 && category <= 12)
		{
			if (index >= 1 && index <= 10)
			{
				if (!isTopRow)
				{
					LDBTool.SetBuildBar(category, index, itemId);
				}
				else
				{
					if (!isTopRow)
					{
						BuildBarToolPlugin.logger.LogWarning((object)"Bind Build Bar Fail. tier must be 1 or 2.");
						return false;
					}
					if (BuildBarToolPlugin.protoIds[category, index] > 0)
					{
						BuildBarToolPlugin.logger.LogWarning((object)$"Bind Build Bar Fail (item ID:{itemId}). Build bar [{category}, tier2, {index}] is already bound with another item ID:{BuildBarToolPlugin.protoIds[category, index]}.");
						return false;
					}
					BuildBarToolPlugin.protoIds[category, index] = itemId;
				}
				return true;
			}
			BuildBarToolPlugin.logger.LogWarning((object)"Bind Build Bar Fail. index must be between 1 and 10.");
			return false;
		}
		BuildBarToolPlugin.logger.LogWarning((object)"Bind Build Bar Fail. category must be between 1 and 12.");
		return false;
	}

	public static void SetBuildBar(this ItemProto proto, int buildIndex, bool isTopRow)
	{
		SetBuildBar(buildIndex / 100, buildIndex % 100, ((Proto)proto).ID, isTopRow);
		if (isTopRow)
		{
			proto.BuildIndex = 0;
		}
	}

	public static void SetBuildBar(this ItemProto proto, int category, int index, bool isTopRow)
	{
		SetBuildBar(category, index, ((Proto)proto).ID, isTopRow);
		if (isTopRow)
		{
			proto.BuildIndex = 0;
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry", "TabSystem", "LocalizationModule" })]
[BepInPlugin("Gnimaerd.DSP.plugin.BuildBarTool", "BuildBarTool", "1.0.1")]
public class BuildBarToolPlugin : BaseUnityPlugin
{
	public const string GUID = "Gnimaerd.DSP.plugin.BuildBarTool";

	public const string NAME = "BuildBarTool";

	public const string VERSION = "1.0.1";

	internal static bool developerMode = true;

	public static ConfigFile customBarBind = new ConfigFile(Paths.ConfigPath + "/RebindBuildBar/CustomBarBindTier2.cfg", true);

	internal static ManualLogSource logger;

	public static List<GameObject> childButtonObjs = new List<GameObject>();

	public static List<UIButton> childButtons = new List<UIButton>();

	public static List<Image> childIcons = new List<Image>();

	public static List<Text> childNumTexts = new List<Text>();

	public static List<Text> childTips = new List<Text>();

	public static int[,] protoIds = new int[16, 13];

	public static ItemProto[,] protos = new ItemProto[16, 13];

	public static bool[] extendedCategories = new bool[16];

	public static List<CanvasGroup> childCanvasGroups = new List<CanvasGroup>();

	public static List<Text> childHotkeyText = new List<Text>();

	public static List<Text> oriChildHotkeyText = new List<Text>();

	public static GameObject switchHotkeyRowText;

	public static int hotkeyActivateRow = 0;

	public static float secondLevelAlpha = 1f;

	public static int dblClickIndex = 0;

	public static double dblClickTime = 0.0;

	public static bool forceShowAllButtons = false;

	public static bool GenesisCompatibility = false;

	public static bool RebindBuildBarCompatibility = false;

	public static Color textColor = new Color(0.3821f, 0.8455f, 1f, 0.7843f);

	public static Color lockedTextColor = new Color(0.8f, 0f, 0f, 0.5f);

	public static Color normalColor = new Color(0.588f, 0.588f, 0.588f, 0.7f);

	public static Color disabledColor = new Color(0.2f, 0.15f, 0.15f, 0.7f);

	public static Color disabledColor2 = new Color(0.316f, 0.281f, 0.281f, 0.7f);

	public static string lockedText = "";

	public void Awake()
	{
		BBTProtos.AddLocalizationProtos();
		logger = ((BaseUnityPlugin)this).Logger;
		InitStaticData();
		Harmony.CreateAndPatchAll(typeof(BuildBarToolPlugin), (string)null);
	}

	public void Start()
	{
		InitAll();
	}

	public void Update()
	{
	}

	public static void InitAll()
	{
		InitUI();
	}

	public static void InitStaticData()
	{
		for (int i = 0; i < extendedCategories.Length; i++)
		{
			extendedCategories[i] = false;
		}
		for (int j = 0; j < 16; j++)
		{
			for (int k = 0; k < 13; k++)
			{
				protoIds[j, k] = 0;
			}
		}
	}

	public static void InitUI()
	{
		//IL_0028: 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_0050: 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_008e: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_01b5: Expected O, but got Unknown
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/bg-trans");
		GameObject val2 = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/bg-trans/sandbox-btn");
		GameObject val3 = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/bg-trans/sandbox-btn/title");
		float x = val.GetComponent<RectTransform>().sizeDelta.x;
		val.GetComponent<RectTransform>().sizeDelta = new Vector2(x, 228f);
		float x2 = val2.GetComponent<RectTransform>().sizeDelta.x;
		val2.GetComponent<RectTransform>().sizeDelta = new Vector2(x2, 228f);
		val3.transform.rotation = Quaternion.AngleAxis(77f, new Vector3(0f, 0f, 1f));
		val3.transform.localPosition = new Vector3(81f, -50f, 0f);
		GameObject val4 = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/child-group/button-1");
		Transform transform = GameObject.Find("UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/child-group").transform;
		UIButton component = val4.GetComponent<UIButton>();
		float x3 = val4.transform.localPosition.x;
		float y = val4.transform.localPosition.y;
		for (int i = 0; i < 11; i++)
		{
			GameObject val5 = Object.Instantiate<GameObject>(val4, transform);
			((Object)val5).name = $"button-up-{i}";
			val5.transform.localPosition = new Vector3(x3 + (float)(i * 52) - 52f, y + 60f, 0f);
			val5.AddComponent<CanvasGroup>();
			Object.DestroyImmediate((Object)(object)val5.GetComponent<Button>());
			val5.AddComponent<Button>();
			string ii = i.ToString();
			((UnityEvent)val5.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				OnChildButtonClick(Convert.ToInt32(ii));
			});
			UIButton component2 = val5.GetComponent<UIButton>();
			component2.button = val5.GetComponent<Button>();
			childButtonObjs.Add(val5);
			childButtons.Add(component2);
			childIcons.Add(((Component)val5.transform.Find("icon")).GetComponent<Image>());
			childNumTexts.Add(((Component)val5.transform.Find("count")).GetComponent<Text>());
			childCanvasGroups.Add(val5.GetComponent<CanvasGroup>());
			childHotkeyText.Add(((Component)val5.transform.Find("text")).GetComponent<Text>());
		}
		for (int j = 0; j < 10; j++)
		{
			oriChildHotkeyText.Add(GameObject.Find($"UI Root/Overlay Canvas/In Game/Function Panel/Build Menu/child-group/button-{j + 1}/text").GetComponent<Text>());
		}
		GameObject gameObject = ((Component)val4.transform.Find("text")).gameObject;
		switchHotkeyRowText = Object.Instantiate<GameObject>(gameObject, transform);
		((Object)switchHotkeyRowText).name = "switch-note-text";
		switchHotkeyRowText.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 160f);
		switchHotkeyRowText.GetComponent<Text>().text = Localization.Translate("切换快捷键");
		switchHotkeyRowText.GetComponent<Text>().fontSize = 14;
		int num = 155;
		if (RebindBuildBarCompatibility)
		{
			num = 180;
		}
		switchHotkeyRowText.transform.localPosition = new Vector3(200f, (float)num, 0f);
		if (GenesisCompatibility)
		{
			switchHotkeyRowText.transform.localPosition = new Vector3(190f, (float)num, 0f);
		}
		childCanvasGroups.Add(switchHotkeyRowText.AddComponent<CanvasGroup>());
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(VFPreload_Patch), "VFPreloadPostPatch")]
	public static void PostLoadData()
	{
		for (int i = 0; i < 16; i++)
		{
			for (int j = 0; j < 13; j++)
			{
				if (protoIds[i, j] > 0)
				{
					ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(protoIds[i, j]);
					if (val != null)
					{
						protos[i, j] = val;
						logger.LogInfo((object)$"Set build bar at {i},{j} (tier 2) ID:{((Proto)val).ID} name:{Localization.Translate(((Proto)val).Name)}");
						extendedCategories[i] = true;
					}
					else
					{
						logger.LogWarning((object)$"Set Build Bar Fail because item ID:{protoIds[i, j]} is null.");
					}
				}
			}
		}
		LoadFromBuildIndex();
		lockedText = Localization.Translate("gmLockedItemText");
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIBuildMenu), "StaticLoad")]
	public static bool StaticLoadPrefix()
	{
		if (!UIBuildMenu.staticLoaded)
		{
			LoadFromBuildIndex();
		}
		return true;
	}

	public static void LoadFromBuildIndex()
	{
		for (int i = 0; i < ((ProtoSet<ItemProto>)(object)LDB.items).dataArray.Length; i++)
		{
			int buildIndex = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray[i].BuildIndex;
			if (buildIndex > 0)
			{
				int num = buildIndex / 100;
				int num2 = buildIndex % 100 - 20;
				if (num <= 15 && num2 >= 0 && num2 <= 12)
				{
					protoIds[num, num2] = ((Proto)((ProtoSet<ItemProto>)(object)LDB.items).dataArray[i]).ID;
					protos[num, num2] = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray[i];
					extendedCategories[num] = true;
					logger.LogInfo((object)$"Set build bar at {num},{num2} (tier 2) from ItemProto.BuildIndex, ID:{((Proto)((ProtoSet<ItemProto>)(object)LDB.items).dataArray[i]).ID} name:{Localization.Translate(((Proto)((ProtoSet<ItemProto>)(object)LDB.items).dataArray[i]).Name)}");
				}
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIFunctionPanel), "_OnUpdate")]
	public static void UIBuildMenuOnUpdatePostPatch(ref UIFunctionPanel __instance)
	{
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Invalid comparison between Unknown and I4
		UIFunctionPanel val = __instance;
		bool guideComplete = GameMain.data.guideComplete;
		float num = 0f;
		val.posWanted = -60f;
		if (guideComplete)
		{
			if (((ManualBehaviour)val.buildMenu).active)
			{
				if (extendedCategories[val.buildMenu.currentCategory] || forceShowAllButtons)
				{
					bool flag = forceShowAllButtons;
					UIRoot instance = UIRoot.instance;
					if (instance != null)
					{
						UIGame uiGame = instance.uiGame;
						if (uiGame != null)
						{
							UIBuildMenu buildMenu = uiGame.buildMenu;
							if (buildMenu != null)
							{
								_ = buildMenu.showButtonsAnyways;
								if (true)
								{
									flag = flag || UIRoot.instance.uiGame.buildMenu.showButtonsAnyways;
								}
							}
						}
					}
					GameHistoryData history = GameMain.data.history;
					int currentCategory = val.buildMenu.currentCategory;
					for (int i = 0; i < 12; i++)
					{
						int num2 = ((Proto)(protos[currentCategory, i]?)).ID ?? 0;
						if (num2 > 0 && history.ItemUnlocked(num2))
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						val.posWanted = 0f;
					}
					else
					{
						val.posWanted = -135f;
						num = -75f;
					}
				}
				else
				{
					val.posWanted = -135f;
					num = -75f;
				}
				if (val.buildMenu.isDismantleMode)
				{
					val.posWanted = -75f;
				}
				if (val.buildMenu.isUpgradeMode)
				{
					val.posWanted = -75f;
				}
			}
			else if (((ManualBehaviour)val.sandboxMenu).active)
			{
				if (val.sandboxMenu.childGroup.activeSelf)
				{
					val.posWanted = -60f;
				}
				else
				{
					val.posWanted = -135f;
					num = -75f;
				}
				if (val.sandboxMenu.isRemovalMode)
				{
					val.posWanted = -75f;
				}
			}
			else if ((int)val.mainPlayer.controller.actionBuild.blueprintMode > 0)
			{
				val.posWanted = -193f;
				num = -133f;
			}
			else
			{
				val.posWanted = -195f;
				num = -135f;
			}
		}
		else
		{
			val.posWanted = -195f;
			num = -135f;
		}
		float num3 = num;
		float pos = val.pos;
		float num4 = 18f;
		if (!((double)Mathf.Abs(num3 - pos) < 1E-05))
		{
			float deltaTime = Time.deltaTime;
			float num6;
			if (deltaTime > 0.01f)
			{
				float num5 = 1f - num4 * 0.01f;
				num6 = 1f - Mathf.Pow(num5, deltaTime * 100f);
			}
			else
			{
				num6 = num4 * deltaTime;
			}
			val.pos = (val.pos - num6 * num3) / (1f - num6);
		}
		val.pos = Lerp.Tween(val.pos, val.posWanted, 18f);
		val.sandboxTitleObject.SetActive(val.pos > -150f);
		val.sandboxIconObject.SetActive(val.pos <= -150f);
		val.bgTrans.anchoredPosition = new Vector2(val.bgTrans.anchoredPosition.x, val.pos);
		val.sandboxRect.anchoredPosition = new Vector2(Mathf.Clamp((0f - val.pos) * 2f - 320f, -50f, 10f), 0f);
		if (val.pos > -10f)
		{
			float num7 = Mathf.Clamp01(secondLevelAlpha + 0.02f);
			if (secondLevelAlpha != num7)
			{
				secondLevelAlpha = num7;
				for (int j = 0; j < childCanvasGroups.Count; j++)
				{
					childCanvasGroups[j].alpha = secondLevelAlpha;
				}
			}
		}
		else
		{
			secondLevelAlpha = 0f;
			for (int k = 0; k < childCanvasGroups.Count; k++)
			{
				childCanvasGroups[k].alpha = secondLevelAlpha;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIBuildMenu), "SetCurrentCategory")]
	public static void UIBuildMenuSetCurrentCategoryPostPatch(ref UIBuildMenu __instance, int category)
	{
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu val = __instance;
		if (val.player == null)
		{
			return;
		}
		int currentCategory = val.currentCategory;
		val.currentCategory = category;
		if (currentCategory != val.currentCategory)
		{
			val.player.controller.actionPick.pickMode = false;
		}
		GameHistoryData history = GameMain.history;
		if (extendedCategories[category] || RebindBuildBarCompatibility)
		{
			StorageComponent package = val.player.package;
			for (int i = 1; i < 11; i++)
			{
				if (!((Object)(object)childButtons[i] != (Object)null))
				{
					continue;
				}
				if (protos[category, i] != null && (protos[category, i].IsEntity || protos[category, i].BuildMode == 4))
				{
					int iD = ((Proto)protos[category, i]).ID;
					if (history.ItemUnlocked(iD) || RebindBuildBarCompatibility)
					{
						int num = package.GetItemCount(((Proto)protos[category, i]).ID);
						if (DeliverySlotsTweaksCompat.enabled)
						{
							num += val.player.deliveryPackage.GetItemCount(iD);
						}
						if (((Proto)protos[category, i]).ID == val.player.inhandItemId)
						{
							num += val.player.inhandItemCount;
						}
						((Behaviour)childIcons[i]).enabled = true;
						childButtons[i].OnEnable();
						((Graphic)childIcons[i]).color = normalColor;
						childButtons[i].transitions[1].normalColor = normalColor;
						childIcons[i].sprite = protos[category, i].iconSprite;
						StringBuilderUtility.WriteKMG(val.strb, 5, (long)num, false);
						childNumTexts[i].text = ((num > 0) ? val.strb.ToString().Trim() : "");
						((Graphic)childNumTexts[i]).color = textColor;
						((Selectable)childButtons[i].button).interactable = true;
						if (!history.ItemUnlocked(iD))
						{
							childNumTexts[i].text = lockedText;
							((Graphic)childNumTexts[i]).color = lockedTextColor;
							((Graphic)childIcons[i]).color = disabledColor2;
							childButtons[i].transitions[1].normalColor = disabledColor2;
						}
						childButtonObjs[i].SetActive(true);
					}
					else
					{
						childButtonObjs[i].SetActive(false);
						((Behaviour)childIcons[i]).enabled = false;
						childIcons[i].sprite = null;
						StringBuilderUtility.WriteKMG(val.strb, 5, 0L, false);
						childNumTexts[i].text = "";
					}
				}
				else
				{
					childButtonObjs[i].SetActive(false);
					((Behaviour)childIcons[i]).enabled = false;
					childIcons[i].sprite = null;
					StringBuilderUtility.WriteKMG(val.strb, 5, 0L, false);
					childNumTexts[i].text = "";
				}
			}
		}
		else
		{
			for (int j = 1; j < 11; j++)
			{
				((Component)childButtons[j]).gameObject.SetActive(false);
				childIcons[j].sprite = null;
				StringBuilderUtility.WriteKMG(val.strb, 5, 0L, false);
				childNumTexts[j].text = "";
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIBuildMenu), "_OnUpdate")]
	public static bool UIBuildMenuOnUpdatePrePatch(ref UIBuildMenu __instance)
	{
		bool inputing = VFInput.inputing;
		if (extendedCategories[__instance.currentCategory] && hotkeyActivateRow == 1)
		{
			VFInput.inputing = true;
		}
		for (int i = 0; i < 10; i++)
		{
			if (Input.GetKeyDown((KeyCode)(49 + (i - 1))))
			{
				VFInput.inputing = inputing;
				break;
			}
		}
		if (Input.GetKeyDown((KeyCode)45) || Input.GetKeyDown((KeyCode)117) || Input.GetKeyDown((KeyCode)120))
		{
			VFInput.inputing = inputing;
		}
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIBuildMenu), "_OnUpdate")]
	public static void UIBuildMenuOnUpdatePostPatch(ref UIBuildMenu __instance)
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_046f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu val = __instance;
		int currentCategory = val.currentCategory;
		if (extendedCategories[currentCategory] || forceShowAllButtons)
		{
			GameHistoryData history = GameMain.history;
			StorageComponent package = val.player.package;
			VFInput.inputing = (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject.GetComponent<InputField>() != (Object)null;
			if (val.childGroup.gameObject.activeSelf && hotkeyActivateRow == 1)
			{
				for (int i = 1; i <= 10; i++)
				{
					if (Input.GetKeyDown((KeyCode)(282 + (i - 1))) && VFInput.inScreen && VFInput.readyToBuild && !VFInput.inputing)
					{
						val.isKeyDownCallingAudio = true;
						OnChildButtonClick(i);
						VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
					}
				}
			}
			for (int j = 1; j < 12 && j < childNumTexts.Count; j++)
			{
				if (protos[currentCategory, j] != null)
				{
					int iD = ((Proto)protos[currentCategory, j]).ID;
					bool flag = history.ItemUnlocked(iD) || val.showButtonsAnyways;
					if (flag || (RebindBuildBarCompatibility && forceShowAllButtons))
					{
						((Behaviour)childIcons[j]).enabled = true;
						((Graphic)childIcons[j]).color = normalColor;
						childButtons[j].transitions[1].normalColor = normalColor;
						childButtons[j].OnEnable();
						childButtons[j].tips.itemId = iD;
						childButtons[j].tips.itemInc = 0;
						childButtons[j].tips.itemCount = 0;
						childButtons[j].tips.corner = 8;
						childButtons[j].tips.delay = 0.2f;
						childButtons[j].tips.type = (ItemTipType)2;
						int num = package.GetItemCount(iD);
						bool flag2 = val.player.inhandItemId == iD;
						if (flag2)
						{
							num += val.player.inhandItemCount;
						}
						if (DeliverySlotsTweaksCompat.enabled)
						{
							num += val.player.deliveryPackage.GetItemCount(iD);
						}
						StringBuilderUtility.WriteKMG(val.strb, 5, (long)num, false);
						childNumTexts[j].text = ((num > 0) ? val.strb.ToString().Trim() : "");
						((Graphic)childNumTexts[j]).color = textColor;
						((Selectable)childButtons[j].button).interactable = true;
						if ((Object)(object)childIcons[j].sprite == (Object)null && protos[currentCategory, j] != null)
						{
							childIcons[j].sprite = protos[currentCategory, j].iconSprite;
						}
						childButtons[j].highlighted = flag2;
						if (!flag)
						{
							childNumTexts[j].text = lockedText;
							((Graphic)childNumTexts[j]).color = lockedTextColor;
							((Graphic)childIcons[j]).color = disabledColor2;
							childButtons[j].transitions[1].normalColor = disabledColor2;
						}
						((Component)childButtons[j].button).gameObject.SetActive(true);
					}
					else
					{
						childButtons[j].tips.itemId = 0;
						childButtons[j].tips.itemInc = 0;
						childButtons[j].tips.itemCount = 0;
						childButtons[j].tips.type = (ItemTipType)2;
						((Selectable)childButtons[j].button).interactable = false;
						childButtonObjs[j].SetActive(false);
					}
				}
				else if (forceShowAllButtons)
				{
					((Behaviour)childIcons[j]).enabled = false;
					((Selectable)childButtons[j].button).interactable = true;
					childButtons[j].tips.itemId = 0;
					((Component)childButtons[j].button).gameObject.SetActive(true);
				}
				else
				{
					((Component)childButtons[j].button).gameObject.SetActive(false);
				}
			}
			if (Input.GetKeyDown((KeyCode)301))
			{
				hotkeyActivateRow = (hotkeyActivateRow + 1) % 2;
			}
			RefreshHotKeyRow();
		}
		else
		{
			RefreshHotKeyRow(force0: true);
		}
	}

	public static void OnChildButtonClick(int index)
	{
		//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu buildMenu = UIRoot.instance.uiGame.buildMenu;
		int currentCategory = buildMenu.currentCategory;
		if (currentCategory < 0 || currentCategory > protos.Length)
		{
			return;
		}
		bool flag = false;
		if (buildMenu.player == null || protos[currentCategory, index] == null)
		{
			return;
		}
		int iD = ((Proto)protos[currentCategory, index]).ID;
		if (!buildMenu.showButtonsAnyways && !GameMain.history.ItemUnlocked(iD))
		{
			return;
		}
		if (index == dblClickIndex && GameMain.gameTime - dblClickTime < 0.33000001311302185)
		{
			UIRoot.instance.uiGame.FocusOnReplicate(iD);
			dblClickTime = 0.0;
			dblClickIndex = 0;
			flag = true;
		}
		dblClickIndex = index;
		dblClickTime = GameMain.gameTime;
		for (int i = 0; i < buildMenu.randRemindTips.Length; i++)
		{
			if ((Object)(object)buildMenu.randRemindTips[i] != (Object)null && ((ManualBehaviour)buildMenu.randRemindTips[i]).active)
			{
				int featureId = buildMenu.randRemindTips[i].featureId;
				int num = featureId / 100;
				int num2 = featureId % 100;
				if (currentCategory == num && index == num2)
				{
					((ManualBehaviour)buildMenu.randRemindTips[i])._Close();
				}
			}
		}
		int num3 = buildMenu.player.package.GetItemCount(iD);
		if (DeliverySlotsTweaksCompat.enabled)
		{
			num3 += buildMenu.player.deliveryPackage.GetItemCount(iD);
		}
		if (num3 <= 0 && BuildToolOptCompat.enabled && BuildToolOptCompat.hologramEnabled)
		{
			num3 = 999;
		}
		if (num3 <= 0 && (currentCategory != 9 || index != 1))
		{
			if (!flag)
			{
				GameMain.data.warningSystem.Broadcast((EBroadcastVocal)22, -1, 0, 0);
				UIRealtimeTip.Popup(Localization.Translate("双击打开合成器"), true, 2);
			}
			return;
		}
		if (buildMenu.player.inhandItemId == iD)
		{
			buildMenu.player.SetHandItems(0, 0, 0);
		}
		else if (num3 > 0 || (currentCategory == 9 && index == 1))
		{
			buildMenu.player.SetHandItems(iD, 0, 0);
		}
		else
		{
			buildMenu.player.SetHandItems(0, 0, 0);
		}
		if (buildMenu.isKeyDownCallingAudio)
		{
			VFAudio.Create("build-menu-child", (Transform)null, Vector3.zero, false, 0, -1, -1L).Play();
			buildMenu.isKeyDownCallingAudio = false;
		}
	}

	public static void RefreshHotKeyRow(bool force0 = false)
	{
		bool flag = hotkeyActivateRow == 0;
		bool flag2 = hotkeyActivateRow == 1;
		if (force0)
		{
			flag = true;
			flag2 = false;
		}
		for (int i = 0; i < 10; i++)
		{
			oriChildHotkeyText[i].text = (flag ? $"F{i + 1}" : "");
		}
		for (int j = 0; j < 11; j++)
		{
			childHotkeyText[j].text = (flag2 ? $"F{j}" : "");
		}
	}

	public static void RefreshCategoryIfExtended(int category)
	{
		if (category < 0 || category > extendedCategories.Length)
		{
			return;
		}
		extendedCategories[category] = false;
		for (int i = 0; i < 13; i++)
		{
			if (protos[category, i] != null)
			{
				extendedCategories[category] = true;
				break;
			}
		}
	}
}
public static class BuildToolOptCompat
{
	public const string MODGUID = "starfi5h.plugin.BuildToolOpt";

	internal static bool enabled;

	internal static bool hologramEnabled;

	public static void Compatible()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		enabled = Chainloader.PluginInfos.TryGetValue("starfi5h.plugin.BuildToolOpt", out var _);
		hologramEnabled = false;
		if (enabled)
		{
			Harmony val = new Harmony("Gnimaerd.DSP.plugin.BuildBarTool.Compatibility.BuildToolOpt");
			val.PatchAll(typeof(BuildToolOptCompat));
		}
	}

	public static void Start()
	{
		hologramEnabled = Plugin.EnableHologram;
	}
}
[BepInPlugin("Gnimaerd.DSP.plugin.BuildBarTool.CheckPlugins", "BuildBarTool.CheckPlugins", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CompatCheck : BaseUnityPlugin
{
	public const string GUID = "Gnimaerd.DSP.plugin.BuildBarTool.CheckPlugins";

	public const string NAME = "BuildBarTool.CheckPlugins";

	public const string VERSION = "1.0.1";

	public static ManualLogSource Log;

	public void Awake()
	{
		DeliverySlotsTweaksCompat.Compatible();
		BuildToolOptCompat.Compatible();
	}

	public void Start()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		try
		{
			if (BuildToolOptCompat.enabled)
			{
				BuildToolOptCompat.Start();
			}
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)"Error in BuildBarTool.CompatCheck Start()");
			Log.LogWarning((object)ex);
		}
	}
}
public static class DeliverySlotsTweaksCompat
{
	public const string MODGUID = "starfi5h.plugin.DeliverySlotsTweaks";

	internal static bool enabled;

	public static void Compatible()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		enabled = Chainloader.PluginInfos.TryGetValue("starfi5h.plugin.DeliverySlotsTweaks", out var _);
		if (enabled)
		{
			Harmony val = new Harmony("Gnimaerd.DSP.plugin.BuildBarTool.Compatibility.DeliverySlotsTweaksCompat");
			val.PatchAll(typeof(DeliverySlotsTweaksCompat));
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Gnimaerd.DSP.plugin.BuildBarTool_RebindBuildBarCompat", "BuildBarTool_RebindBuildBarCompat", "0.1.0")]
internal class RebindBuildBarCompat : BaseUnityPlugin
{
	public const string GUID = "Gnimaerd.DSP.plugin.BuildBarTool_RebindBuildBarCompat";

	public const string NAME = "BuildBarTool_RebindBuildBarCompat";

	public const string VERSION = "0.1.0";

	internal static ManualLogSource logger;

	public static Vector2 pickerPos = new Vector2(-300f, 238f);

	public void Awake()
	{
		logger = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(typeof(RebindBuildBarCompat), (string)null);
		BuildBarToolPlugin.RebindBuildBarCompatibility = true;
	}

	public void Start()
	{
	}

	public void Update()
	{
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu buildMenu = Patches.buildMenu;
		if ((Object)(object)buildMenu == (Object)null || !buildMenu.childGroup.gameObject.activeSelf || buildMenu.currentCategory < 1 || buildMenu.currentCategory >= 9)
		{
			return;
		}
		if (CustomKeyBindSystem.GetKeyBind("ReassignBuildBar").keyValue)
		{
			BuildBarToolPlugin.forceShowAllButtons = true;
		}
		else
		{
			BuildBarToolPlugin.forceShowAllButtons = false;
		}
		if (!CustomKeyBindSystem.GetKeyBind("ClearBuildBar").keyValue)
		{
			return;
		}
		for (int i = 1; i <= 10; i++)
		{
			if (BuildBarToolPlugin.childButtons[i].isPointerEnter)
			{
				int num = buildMenu.currentCategory * 100 + i;
				ConfigEntry<int> val = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", num.ToString(), 0, "Cleared by player");
				val.Value = 0;
				BuildBarToolPlugin.protos[buildMenu.currentCategory, i] = null;
				buildMenu.SetCurrentCategory(buildMenu.currentCategory);
				VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
				BuildBarToolPlugin.RefreshCategoryIfExtended(buildMenu.currentCategory);
				break;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(BuildBarToolPlugin), "PostLoadData")]
	public static void LoadConfigFile()
	{
		for (int i = 0; i < 16; i++)
		{
			for (int j = 1; j < 11; j++)
			{
				int num = i * 100 + j;
				ItemProto val = BuildBarToolPlugin.protos[i, j];
				if (val != null && ((Proto)val).ID != 0)
				{
					ConfigEntry<int> val2 = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", num.ToString(), ((Proto)val).ID, "Item: " + Localization.Translate(((Proto)val).Name));
					if (val2.Value == 0)
					{
						BuildBarToolPlugin.protos[i, j] = null;
					}
					else if (val2.Value > 0 && ((ProtoSet<ItemProto>)(object)LDB.items).Exist(val2.Value) && val2.Value != ((Proto)val).ID)
					{
						BuildBarToolPlugin.protos[i, j] = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val2.Value);
					}
					else if (val2.Value < 0)
					{
						val2.Value = ((Proto)val).ID;
					}
				}
				else
				{
					ConfigEntry<int> val3 = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", num.ToString(), -1, "Unused");
					if (val3.Value > 0 && ((ProtoSet<ItemProto>)(object)LDB.items).Exist(val3.Value))
					{
						BuildBarToolPlugin.protos[i, j] = ((ProtoSet<ItemProto>)(object)LDB.items).Select(val3.Value);
						BuildBarToolPlugin.extendedCategories[i] = true;
					}
				}
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(Patches), "ResetBuildBarItems")]
	public static void ReloadOneCategoryPostfix(bool heldCtrl)
	{
		if (heldCtrl)
		{
			for (int i = 1; i < 16; i++)
			{
				BuildBarToolPlugin.extendedCategories[i] = false;
				for (int j = 1; j < 13; j++)
				{
					if (BuildBarToolPlugin.protoIds[i, j] > 0)
					{
						ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(BuildBarToolPlugin.protoIds[i, j]);
						if (val != null)
						{
							BuildBarToolPlugin.protos[i, j] = val;
							BuildBarToolPlugin.extendedCategories[i] = true;
						}
						else
						{
							BuildBarToolPlugin.protos[i, j] = null;
						}
					}
					else
					{
						BuildBarToolPlugin.protos[i, j] = null;
					}
				}
			}
		}
		else
		{
			int currentCategory = Patches.buildMenu.currentCategory;
			BuildBarToolPlugin.extendedCategories[currentCategory] = false;
			for (int k = 1; k < 13; k++)
			{
				if (BuildBarToolPlugin.protoIds[currentCategory, k] > 0)
				{
					ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(BuildBarToolPlugin.protoIds[currentCategory, k]);
					if (val2 != null)
					{
						BuildBarToolPlugin.protos[currentCategory, k] = val2;
						BuildBarToolPlugin.extendedCategories[currentCategory] = true;
					}
					else
					{
						BuildBarToolPlugin.protos[currentCategory, k] = null;
					}
				}
				else
				{
					BuildBarToolPlugin.protos[currentCategory, k] = null;
				}
			}
		}
		SetConfigFile();
		BuildBarToolPlugin.customBarBind.Save();
	}

	public static void SetConfigFile()
	{
		for (int i = 0; i < BuildBarToolPlugin.extendedCategories.Length; i++)
		{
			BuildBarToolPlugin.extendedCategories[i] = false;
		}
		for (int j = 0; j < 16; j++)
		{
			if (j != Patches.buildMenu.currentCategory && !CustomKeyBindSystem.GetKeyBind("ReassignBuildBar").keyValue)
			{
				continue;
			}
			for (int k = 1; k < 13; k++)
			{
				int num = j * 100 + k;
				if (BuildBarToolPlugin.protos[j, k] != null)
				{
					ItemProto val = BuildBarToolPlugin.protos[j, k];
					ConfigEntry<int> val2 = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", num.ToString(), ((Proto)val).ID, "Item: " + Localization.Translate(((Proto)val).Name));
					val2.Value = ((Proto)val).ID;
					BuildBarToolPlugin.extendedCategories[j] = true;
				}
				else
				{
					ConfigEntry<int> val3 = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", num.ToString(), -1, "Unused");
					val3.Value = -1;
				}
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(Patches), "Update")]
	public static bool RebindBuildBarPatchesUpdatePrefix()
	{
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu buildMenu = Patches.buildMenu;
		if ((Object)(object)buildMenu == (Object)null || !buildMenu.childGroup.gameObject.activeSelf)
		{
			return false;
		}
		if (buildMenu.currentCategory < 1 || buildMenu.currentCategory >= 9)
		{
			return false;
		}
		if (CustomKeyBindSystem.GetKeyBind("ReassignBuildBar").keyValue && BuildBarToolPlugin.hotkeyActivateRow == 1)
		{
			for (int i = 1; i <= 10; i++)
			{
				if (!Input.GetKeyDown((KeyCode)(282 + (i - 1))) || !VFInput.inScreen || VFInput.inputing)
				{
					continue;
				}
				int buildIndex = buildMenu.currentCategory * 100 + i;
				UIItemPickerExtension.Popup(pickerPos, (Action<ItemProto>)delegate(ItemProto proto)
				{
					//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
					if (proto != null && ((Proto)proto).ID != 0)
					{
						ConfigEntry<int> val = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", buildIndex.ToString(), ((Proto)proto).ID, "Item: " + Localization.Translate(((Proto)proto).Name));
						val.Value = ((Proto)proto).ID;
						BuildBarToolPlugin.protos[buildMenu.currentCategory, i] = proto;
						BuildBarToolPlugin.extendedCategories[buildMenu.currentCategory] = true;
						buildMenu.SetCurrentCategory(buildMenu.currentCategory);
						VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
					}
				}, true, (Func<ItemProto, bool>)((ItemProto proto) => proto.ModelIndex != 0 && proto.CanBuild));
				UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(2);
				return false;
			}
			return false;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(BuildBarToolPlugin), "OnChildButtonClick")]
	public static bool OnChildButtonClickPrefix(int index)
	{
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		UIBuildMenu buildMenu = Patches.buildMenu;
		if ((Object)(object)buildMenu == (Object)null || !buildMenu.childGroup.gameObject.activeSelf)
		{
			return false;
		}
		if (buildMenu.currentCategory < 1 || buildMenu.currentCategory >= 9)
		{
			return false;
		}
		if (CustomKeyBindSystem.GetKeyBind("ReassignBuildBar").keyValue)
		{
			int buildIndex = buildMenu.currentCategory * 100 + index;
			UIItemPickerExtension.Popup(pickerPos, (Action<ItemProto>)delegate(ItemProto proto)
			{
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				if (proto != null && ((Proto)proto).ID != 0)
				{
					ConfigEntry<int> val = BuildBarToolPlugin.customBarBind.Bind<int>("BuildBarBinds", buildIndex.ToString(), ((Proto)proto).ID, "Item: " + Localization.Translate(((Proto)proto).Name));
					val.Value = ((Proto)proto).ID;
					BuildBarToolPlugin.protos[buildMenu.currentCategory, index] = proto;
					BuildBarToolPlugin.extendedCategories[buildMenu.currentCategory] = true;
					buildMenu.SetCurrentCategory(buildMenu.currentCategory);
					VFAudio.Create("ui-click-0", (Transform)null, Vector3.zero, true, 0, -1, -1L);
				}
			}, true, (Func<ItemProto, bool>)((ItemProto proto) => proto.ModelIndex != 0 && proto.CanBuild));
			UIRoot.instance.uiGame.itemPicker.OnTypeButtonClick(2);
			return false;
		}
		return true;
	}
}