Decompiled source of DSP ClearAllInventoryFilters v1.0.0

ClearInventoryFilters.dll

Decompiled 2 years 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("ClearInventoryFilters")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a button in player inventory to clear all filters")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ClearInventoryFilters")]
[assembly: AssemblyTitle("ClearInventoryFilters")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.0")]
	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";

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("ClearInventoryFilters");
			val.PatchAll(typeof(Patch));
		}

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

		public static void OnClearFiltersButtonClick()
		{
			Logger.LogInfo((object)"OnClearFiltersButtonClick called!");
			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_002e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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.0";
	}
}