Decompiled source of DSPAutoSorter v1.2.11

DSPAutoSorter.dll

Decompiled a year ago
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.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 DSPAutoSorter;

[BepInPlugin("Appun.DSP.plugin.AutoSorter", "DSPAutoSorter", "1.2.11")]
[HarmonyPatch]
public class DSPAutoSorter : BaseUnityPlugin
{
	public static DSPAutoSorter self;

	private static ConfigEntry<bool> enableForcedSort;

	private static ConfigEntry<bool> enableSortInInventry;

	private static ConfigEntry<bool> enableSortInStorage;

	private static ConfigEntry<bool> enableSortInFuelChamber;

	private static ConfigEntry<bool> enableSortInHanger;

	private static ConfigEntry<bool> enableSortInMiner;

	private static ConfigEntry<bool> enableSortInAssembler;

	private static ConfigEntry<bool> enableSortInBattleBase;

	public static Sprite settingIconSprite;

	public static Sprite squareIconSprite;

	public void Start()
	{
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		LogManager.Logger = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		enableSortInInventry = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInInventry", true, "enable sort in normal inventry.");
		enableSortInStorage = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInStorage", true, "enable sort in storages.");
		enableSortInFuelChamber = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInFuelChamber", true, "enable sort in Mecha fuelchamber.");
		enableSortInHanger = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInHanger", true, "enable sort in Mecha Hanger.");
		enableSortInMiner = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInMiner", true, "enable sort in inventry of miner.");
		enableSortInAssembler = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInAssembler", true, "enable sort in inventry of Assemblers or smelter.");
		enableSortInBattleBase = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableSortInBattleBase", true, "enable sort in inventry of Battlefield Analysis Base.");
		enableForcedSort = ((BaseUnityPlugin)this).Config.Bind<bool>("ForcedSort", "enableForcedSort", true, "enable forced sort.");
		if (enableSortInStorage.Value)
		{
			GameObject gameObject = GameObject.Find("UI Root/Overlay Canvas/In Game/Windows/Storage Window/panel-bg/btn-box").gameObject;
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
		}
		if (enableSortInBattleBase.Value)
		{
			GameObject gameObject2 = GameObject.Find("UI Root/Overlay Canvas/In Game/Windows/Battle Base Window/panel-bg/btn-box").gameObject;
			((Graphic)gameObject2.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStorageGrid), "OnSort")]
	public static bool UIStorageGrid_Sort_Prefix(UIStorageGrid __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		if (((int)__instance.storage.type == 0 || __instance.sortableFilter) && ((Object)((Component)((Component)__instance).transform.parent).gameObject).name == "Player Inventory")
		{
			GameObject gameObject = ((Component)((Component)__instance).transform.parent.Find("panel-bg/btn-box")).gameObject;
			if (enableSortInInventry.Value)
			{
				enableSortInInventry.Value = false;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
			}
			else
			{
				__instance.storage.Sort(true);
				enableSortInInventry.Value = true;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			}
			return false;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStorageWindow), "OnSortClick")]
	public static bool UIStorageWindow_OnSortClick_Prefix(UIStorageWindow __instance)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__instance.storageUI.storage.type == 0 || __instance.storageUI.sortableFilter)
		{
			GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
			if (enableSortInStorage.Value)
			{
				enableSortInStorage.Value = false;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
			}
			else
			{
				__instance.storageUI.storage.Sort(true);
				enableSortInStorage.Value = true;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIBattleBaseWindow), "OnSortClick")]
	public static bool UIBattleBaseWindow_OnSortClick_Prefix(UIBattleBaseWindow __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if ((int)__instance.storage.type == 0 || __instance.storageGrid.sortableFilter)
		{
			GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
			if (enableSortInBattleBase.Value)
			{
				enableSortInBattleBase.Value = false;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
			}
			else
			{
				__instance.storage.Sort(true);
				enableSortInBattleBase.Value = true;
				((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			}
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UIStorageGrid), "OnStorageContentChanged")]
	public static void UIStorageGrid_OnStorageContentChanged_Prefix(UIStorageGrid __instance)
	{
		if (__instance.storage != null && enableForcedSort.Value && __instance.storage.changed)
		{
			GameObject gameObject = ((Component)((Component)__instance).transform.parent).gameObject;
			if (enableSortInInventry.Value && ((Object)gameObject).name == "Player Inventory")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInFuelChamber.Value && ((Object)gameObject).name == "fuel-group")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInHanger.Value && ((Object)gameObject).name == "fighter-storage")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInStorage.Value && ((Object)gameObject).name == "Storage Window")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInMiner.Value && enableSortInInventry.Value && ((Object)gameObject).name == "Miner Window")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInAssembler.Value && enableSortInInventry.Value && ((Object)gameObject).name == "Assembler Window")
			{
				__instance.storage.Sort(true);
			}
			else if (enableSortInBattleBase.Value && ((Object)gameObject).name == "storage-group")
			{
				__instance.storage.Sort(true);
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIInventoryWindow), "_OnOpen")]
	public static void UIGame_OpenPlayerInventory_Postfix(UIInventoryWindow __instance)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
		if (enableSortInInventry.Value)
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			__instance.inventory.storage.Sort(true);
		}
		else
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIMechaWindow), "_OnOpen")]
	public static void UIMechaWindow_OnOpen_Postfix(UIMechaWindow __instance)
	{
		GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
		if (enableSortInFuelChamber.Value)
		{
			GameMain.mainPlayer.mecha.reactorStorage.Sort(true);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIStorageWindow), "_OnOpen")]
	public static void UIStorageWindow_OnOpen_Postfix(UIStorageWindow __instance)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
		if (enableSortInStorage.Value)
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			__instance.storageUI.storage.Sort(true);
		}
		else
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIMinerWindow), "_OnOpen")]
	public static void UIMinerWindow_OnOpen_Postfix(UIMinerWindow __instance)
	{
		if (enableSortInMiner.Value && enableSortInInventry.Value && ((ManualBehaviour)__instance.playerInventory).active)
		{
			AccessTools.FieldRefAccess<UIStorageGrid, StorageComponent>(__instance.playerInventory, "storage").Sort(true);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIAssemblerWindow), "_OnOpen")]
	public static void UIAssemblerWindow_OnOpen_Postfix(UIAssemblerWindow __instance)
	{
		if (enableSortInAssembler.Value && enableSortInInventry.Value && ((ManualBehaviour)__instance.playerInventory).active)
		{
			AccessTools.FieldRefAccess<UIStorageGrid, StorageComponent>(__instance.playerInventory, "storage").Sort(true);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(UIBattleBaseWindow), "_OnOpen")]
	public static void UIBattleBaseWindow_OnOpen_Postfix(UIBattleBaseWindow __instance)
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)((Component)__instance).transform.Find("panel-bg/btn-box")).gameObject;
		if (enableSortInBattleBase.Value)
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(1f, 0.7f, 0f, 1f);
			__instance.storage.Sort(true);
		}
		else
		{
			((Graphic)gameObject.GetComponent<Image>()).color = new Color(0f, 0.174f, 0.216f, 1f);
		}
	}
}
public class LogManager
{
	public static ManualLogSource Logger;
}