Decompiled source of ClearInventoryFilters v1.0.3

ClearInventoryFilters.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ClearInventoryFilters")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds a button in player inventory to clear all filters.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("ClearInventoryFilters")]
[assembly: AssemblyTitle("ClearInventoryFilters")]
[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 ClearAllInventoryFilters
{
	[BepInPlugin("com.antfightclub.dsp.ClearInventoryFilters", "ClearInventoryFilters", "1.0.3")]
	public class ClearFiltersMod : BaseUnityPlugin
	{
		private static class Patch
		{
			internal static bool _initialized;

			[HarmonyPrefix]
			[HarmonyPatch(typeof(GameMain), "Begin")]
			public static void GameMain_Begin_Prefix()
			{
				if (!_initialized)
				{
					_initialized = true;
					CreateUI();
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnClearFiltersButtonClick;
		}

		public const string __NAME__ = "ClearInventoryFilters";

		public const string __GUID__ = "com.antfightclub.dsp.ClearInventoryFilters";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("ClearInventoryFilters").PatchAll(typeof(Patch));
		}

		public static void CreateUI()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00fa: Expected O, but got Unknown
			GameObject gameObject = ((Component)((Component)UIRoot.instance.uiGame.inventoryWindow).gameObject.transform.GetChild(1)).gameObject;
			RectTransform component = gameObject.gameObject.GetComponent<RectTransform>();
			UIButton obj = Object.Instantiate<UIButton>(UIRoot.instance.uiGame.dysonEditor.controlPanel.hierarchy.swarmPanel.orbitButtons[0]);
			NormalizeRectWithTopLeft((Component)(object)obj, 115f, 30f, (Transform)(object)component).sizeDelta = new Vector2(68f, 16f);
			((Component)((Component)obj).transform.Find("frame")).gameObject.SetActive(false);
			Text component2 = ((Component)((Component)obj).transform.Find("Text")).GetComponent<Text>();
			component2.text = "Clear filters";
			component2.fontSize = 12;
			Transform transform = gameObject.transform;
			((Component)obj).transform.SetParent(transform);
			ButtonClickedEvent onClick = obj.button.onClick;
			object obj2 = <>O.<0>__OnClearFiltersButtonClick;
			if (obj2 == null)
			{
				UnityAction val = OnClearFiltersButtonClick;
				<>O.<0>__OnClearFiltersButtonClick = val;
				obj2 = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj2);
		}

		public static void OnClearFiltersButtonClick()
		{
			UIInventoryWindow inventoryWindow = UIRoot.instance.uiGame.inventoryWindow;
			int size = inventoryWindow.inventory.storage.size;
			for (int i = 0; i < size; i++)
			{
				inventoryWindow.inventory.storage.SetFilter(i, 0);
			}
			inventoryWindow.inventory.OnStorageContentChanged();
		}

		public static RectTransform NormalizeRectWithTopLeft(Component cmp, float left, float top, Transform parent = null)
		{
			//IL_0028: 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_0052: 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 transform = cmp.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)(object)parent != (Object)null)
			{
				((Transform)val).SetParent(parent, false);
			}
			val.anchorMax = new Vector2(0f, 1f);
			val.anchorMin = new Vector2(0f, 1f);
			val.pivot = new Vector2(0f, 1f);
			val.anchoredPosition3D = new Vector3(left, 0f - top, 0f);
			return val;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ClearInventoryFilters";

		public const string PLUGIN_NAME = "ClearInventoryFilters";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}