Decompiled source of TCGShopBetterPackOpener v1.0.2

plugins/TCGShopBetterPackOpener.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
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 Newtonsoft.Json;
using TCGShopBetterPackOpener.Cards;
using TCGShopBetterPackOpener.Config;
using TCGShopBetterPackOpener.Extensions;
using TCGShopBetterPackOpener.Globals;
using TCGShopBetterPackOpener.Logging;
using TCGShopBetterPackOpener.Utils;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TCGShopBetterPackOpener")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c4d970d50f8fb1e5f2c7b3106b00cf0172ab10ec")]
[assembly: AssemblyProduct("TCGShopBetterPackOpener")]
[assembly: AssemblyTitle("TCGShopBetterPackOpener")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 TCGShopBetterPackOpener
{
	internal class PackProcessing
	{
		public static bool ReturnEligible = false;

		public static bool PackFromMachine = false;

		public static List<CardData> PackToReturn = new List<CardData>();

		public static InteractableAutoPackOpener CurrentMachine = null;
	}
	public class StoredPackData
	{
		public readonly Dictionary<MachineRef, MachineQueue> Machines = new Dictionary<MachineRef, MachineQueue>();

		public static StoredPackData Instance { get; private set; } = new StoredPackData();

		public MachineRef GetOrAddMachine(InteractableAutoPackOpener machine)
		{
			MachineRef machineRef = new MachineRef(machine);
			if (!Machines.ContainsKey(machineRef))
			{
				Machines[machineRef] = new MachineQueue();
			}
			return machineRef;
		}

		public MachineRef GetMachineAtPos(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			MachineRef key = Machines.FirstOrDefault((KeyValuePair<MachineRef, MachineQueue> m) => m.Key.Position == position).Key;
			if (key != null)
			{
				return key;
			}
			MachineRef key2 = Machines.OrderBy((KeyValuePair<MachineRef, MachineQueue> m) => Vector3.Distance(m.Key.Position, position)).FirstOrDefault().Key;
			if (key2 != null && Vector3.Distance(key2.Position, position) < 0.1f)
			{
				return key2;
			}
			return null;
		}
	}
	public class MachineQueue
	{
		[JsonProperty("queuedPacks")]
		public Dictionary<ECollectionPackType, List<List<CardData>>> QueuedPacks = new Dictionary<ECollectionPackType, List<List<CardData>>>();

		[JsonProperty("queuedItems")]
		public List<EItemType> QueuedItems = new List<EItemType>();
	}
	public class MachineRef(InteractableAutoPackOpener machine) : IEquatable<MachineRef>
	{
		internal InteractableAutoPackOpener Machine => machine;

		public Vector3 Position
		{
			get
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				InteractableAutoPackOpener machine = Machine;
				if (machine == null)
				{
					return Vector3.zero;
				}
				return ((Component)machine).transform.position;
			}
		}

		internal string PositionString => Position.FormattedString();

		public MachineQueue Queue => StoredPackData.Instance.Machines[this];

		public bool Equals(MachineRef other)
		{
			if (other != null)
			{
				return (Object)(object)Machine == (Object)(object)other.Machine;
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is MachineRef other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return ((object)Machine)?.GetHashCode() ?? 0;
		}
	}
	[BepInPlugin("net.ingoh.tcgcardshopsimulator.betterpackopener", "Better Pack Opener", "1.0.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "net.ingoh.tcgcardshopsimulator.betterpackopener";

		public const string PluginName = "Better Pack Opener";

		public const string PluginVer = "1.0.0";

		internal static ManualLogSource Log;

		internal static readonly Harmony Harmony = new Harmony("net.ingoh.tcgcardshopsimulator.betterpackopener");

		internal static string PluginPath;

		public static readonly List<string> ProcessedLog = new List<string>();

		internal static bool Debug = false;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			PluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Instance = this;
			Settings.Instance.Init(((BaseUnityPlugin)this).Config);
		}

		private void OnEnable()
		{
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Better Pack Opener!");
		}

		private void OnDisable()
		{
			Harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Unloaded Better Pack Opener!");
		}

		private void Update()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = Settings.Instance.DebugKeybind.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Debug = !Debug;
				Log.LogInfo((object)("Debug mode " + (Debug ? "enabled" : "disabled") + "."));
			}
		}

		private void OnGUI()
		{
			//IL_001c: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			if (!Debug)
			{
				return;
			}
			GUI.Label(new Rect(10f, 10f, 10000f, 20f), "Better Pack Opener Debug Info");
			GUI.Label(new Rect(10f, 30f, 10000f, 20f), $"Machines: {StoredPackData.Instance.Machines.Count}");
			int num = 50;
			foreach (KeyValuePair<MachineRef, MachineQueue> machine in StoredPackData.Instance.Machines)
			{
				if ((Object)(object)machine.Key.Machine == (Object)null)
				{
					continue;
				}
				GUI.Label(new Rect(10f, (float)num, 10000f, 20f), $"Machine at {machine.Key.PositionString}: {machine.Value.QueuedItems.Count} queued packs");
				num += 20;
				foreach (KeyValuePair<ECollectionPackType, List<List<CardData>>> queuedPack in machine.Value.QueuedPacks)
				{
					GUI.Label(new Rect(30f, (float)num, 10000f, 20f), $"> Pack type {queuedPack.Key}: {queuedPack.Value.Count} queued packs");
					num += 20;
				}
			}
			if ((Object)(object)PackProcessing.CurrentMachine != (Object)null)
			{
				GUI.Label(new Rect(10f, (float)num, 10000f, 20f), "Current packs:");
				num += 20;
				foreach (KeyValuePair<ECollectionPackType, List<List<CardData>>> queuedPack2 in StoredPackData.Instance.GetOrAddMachine(PackProcessing.CurrentMachine).Queue.QueuedPacks)
				{
					foreach (List<CardData> item in queuedPack2.Value)
					{
						GUI.Label(new Rect(30f, (float)num, 10000f, 20f), $"> Pack type {queuedPack2.Key}, cards: {CardUtils.CardsToString(item)} value: {((IEnumerable<CardData>)item).Sum((Func<CardData, float>)CPlayerData.GetCardMarketPrice)}");
						num += 20;
					}
				}
			}
			if (ProcessedLog.Count > 100)
			{
				ProcessedLog.RemoveRange(0, ProcessedLog.Count - 100);
			}
			foreach (string item2 in ProcessedLog.TakeLast((Screen.height - num) / 20 - 1))
			{
				GUI.Label(new Rect(10f, (float)num, 10000f, 20f), item2);
				num += 20;
			}
		}
	}
}
namespace TCGShopBetterPackOpener.Utils
{
	public static class CardUtils
	{
		private static List<string> BorderOrder = new List<string> { "basic", "firstedition", "silver", "gold", "ex", "fullart", "borderless" };

		public static string CardsToString(List<CardData> cardDataList)
		{
			return string.Join(", ", cardDataList.Select((CardData c) => CPlayerData.GetFullCardTypeName(c, false) + " " + InventoryBase.GetMonsterData(c.monsterType).GetName()));
		}

		public static string CardsToShortString(List<CardData> cardDataList)
		{
			return string.Join(" ", cardDataList.Select(GetCardAbbreviatedKeywords));
		}

		public static List<string> GetCardKeywords(CardData card)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected I4, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Expected I4, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected I4, but got Unknown
			List<string> list = new List<string>();
			if (card.isFoil)
			{
				list.Add("foil");
			}
			bool flag = false;
			ECardExpansionType expansionType = card.expansionType;
			switch ((int)expansionType)
			{
			default:
				if ((int)expansionType == 7)
				{
					list.Add("ascension");
					flag = true;
				}
				else
				{
					list.Add(((object)Unsafe.As<ECardExpansionType, ECardExpansionType>(ref card.expansionType)/*cast due to .constrained prefix*/).ToString().ToLower());
				}
				break;
			case 0:
				list.Add("tetramon");
				break;
			case 1:
				list.Add("destiny");
				break;
			case 2:
				list.Add("ghost");
				break;
			}
			list.Add("basic+");
			if (flag)
			{
				ECardBorderType borderType = card.borderType;
				switch ((int)borderType)
				{
				case 0:
					AddBorderAndLower(list, "basic");
					break;
				case 1:
					AddBorderAndLower(list, "silver");
					break;
				case 2:
					AddBorderAndLower(list, "gold");
					break;
				case 3:
					AddBorderAndLower(list, "silver");
					list.Add("fullart");
					list.Add("fullart+");
					break;
				case 4:
					AddBorderAndLower(list, "ex");
					list.Add("fullart");
					list.Add("fullart+");
					break;
				case 5:
					AddBorderAndLower(list, "borderless");
					break;
				}
			}
			else
			{
				ECardBorderType borderType = card.borderType;
				switch ((int)borderType)
				{
				case 0:
					AddBorderAndLower(list, "basic");
					break;
				case 1:
					AddBorderAndLower(list, "firstedition");
					break;
				case 2:
					AddBorderAndLower(list, "silver");
					break;
				case 3:
					AddBorderAndLower(list, "gold");
					break;
				case 4:
					AddBorderAndLower(list, "ex");
					break;
				case 5:
					AddBorderAndLower(list, "fullart");
					break;
				}
			}
			return list;
		}

		public static string GetCardAbbreviatedKeywords(CardData card)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected I4, but got Unknown
			string text = "";
			if (card.isNew)
			{
				text += "N";
			}
			if (card.isFoil)
			{
				text += "F";
			}
			if ((int)card.expansionType == 2)
			{
				return text + "G";
			}
			return text + (int)card.borderType;
		}

		private static void AddBorderAndLower(List<string> list, string border)
		{
			list.Add(border);
			list.Add(border + "+");
			for (int num = BorderOrder.IndexOf(border) - 1; num >= 0; num--)
			{
				list.Add(BorderOrder[num] + "+");
			}
		}
	}
	public static class ItemUtils
	{
		public static Item GiveItemToPlayer(EItemType itemType, Transform parent, Vector3? offset = null, Quaternion? rotation = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			ItemMeshData itemMeshData = InventoryBase.GetItemMeshData(itemType);
			Item item = ItemSpawnManager.GetItem(parent);
			item.SetMesh(itemMeshData.mesh, itemMeshData.material, itemType, itemMeshData.meshSecondary, itemMeshData.materialSecondary, (List<Material>)null);
			((Component)item).transform.localPosition = (Vector3)(((??)offset) ?? Vector3.zero);
			((Component)item).transform.localRotation = (Quaternion)(((??)rotation) ?? Quaternion.identity);
			((Collider)item.m_Collider).enabled = false;
			item.GetOrCreateRigidbody().isKinematic = true;
			CSingleton<InteractionPlayerController>.Instance.AddHoldItemToFront(item);
			((Component)item).gameObject.SetActive(true);
			return item;
		}
	}
}
namespace TCGShopBetterPackOpener.Patches
{
	[HarmonyPatch]
	internal static class CardOpeningSequencePatches
	{
		[HarmonyPatch(typeof(CardOpeningSequence), "GetPackContentCardDataList")]
		[HarmonyPostfix]
		public static void CardOpeningSequence_GetPackContentCardDataList(ref List<CardData> __result)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			if (!Settings.Instance.Enabled.Value || !PackProcessing.ReturnEligible || !CardFilter.FilterPack(__result))
			{
				return;
			}
			PackProcessing.PackToReturn = new List<CardData>();
			foreach (CardData item in __result)
			{
				CardData val = new CardData();
				val.CopyData(item);
				PackProcessing.PackToReturn.Add(val);
			}
			__result.Clear();
		}

		[HarmonyPatch(typeof(CardOpeningSequence), "GetPackContent")]
		[HarmonyPrefix]
		public static bool CardOpeningSequence_GetPackContent(ref CardOpeningSequence __instance, bool clearList, bool isSecondaryRolledData, ECollectionPackType overrideCollectionPackType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			ECollectionPackType val = (((int)overrideCollectionPackType == -1) ? __instance.m_CollectionPackType : overrideCollectionPackType);
			if (PackProcessing.PackFromMachine)
			{
				Logger.LogDebug($"Pack opening sequence initiated by machine, type {val}");
				return true;
			}
			if ((Object)(object)PackProcessing.CurrentMachine == (Object)null)
			{
				return true;
			}
			if (isSecondaryRolledData)
			{
				return false;
			}
			MachineQueue queue = StoredPackData.Instance.GetOrAddMachine(PackProcessing.CurrentMachine).Queue;
			Logger.LogDebug($"Opening pack of type {val}");
			if (queue.QueuedPacks.ContainsKey(val) && queue.QueuedPacks[val].Count > 0)
			{
				Logger.LogDebug($"Returning queued pack of type {val} with cards {CardUtils.CardsToString(queue.QueuedPacks[val][0])}, value {((IEnumerable<CardData>)queue.QueuedPacks[val][0]).Sum((Func<CardData, float>)CPlayerData.GetCardMarketPrice)} (Remaining: {queue.QueuedPacks[val].Count - 1})");
				if (clearList)
				{
					__instance.m_RolledCardDataList.Clear();
				}
				__instance.m_RolledCardDataList.AddRange(queue.QueuedPacks[val][0]);
				__instance.m_HasFoilCard = queue.QueuedPacks[val][0].Any((CardData card) => card.isFoil);
				queue.QueuedPacks[val].RemoveAt(0);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class ForcePackOpenPatches
	{
		[HarmonyPatch(typeof(InteractionPlayerController), "Update")]
		[HarmonyPrefix]
		public static void InteractionPlayerController_Update(InteractionPlayerController __instance)
		{
			if ((Object)(object)PackProcessing.CurrentMachine != (Object)null && !__instance.m_IsInUIMode && !CSingleton<CardOpeningSequence>.Instance.m_IsReadyingToOpen)
			{
				if (StoredPackData.Instance.GetOrAddMachine(PackProcessing.CurrentMachine).Queue.QueuedPacks.Sum((KeyValuePair<ECollectionPackType, List<List<CardData>>> p) => p.Value.Count) == 0)
				{
					PackProcessing.CurrentMachine = null;
				}
				else if (!__instance.CanOpenPack())
				{
					PackProcessing.CurrentMachine = null;
				}
				else if (!CSingleton<CardOpeningSequence>.Instance.m_IsScreenActive)
				{
					__instance.EvaluateOpenCardPack();
				}
			}
		}

		[HarmonyPatch(typeof(InputManager), "GetKeyDownAction")]
		[HarmonyPrefix]
		public static bool InputManager_GetKeyDownAction(EGameAction action, ref bool __result)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)action == 29 && (Object)(object)PackProcessing.CurrentMachine != (Object)null)
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(CardOpeningSequence), "ReadyingCardPack")]
		[HarmonyPostfix]
		public static void CardOpeningSequence_ReadyingCardPack()
		{
			if ((Object)(object)PackProcessing.CurrentMachine != (Object)null)
			{
				InteractionPlayerController.RemoveToolTip((EGameAction)29);
			}
		}
	}
	[HarmonyPatch]
	internal static class PackOpenerPatches
	{
		[HarmonyPatch(typeof(InteractableAutoPackOpener), "OpenPack")]
		[HarmonyPrefix]
		public static void InteractableAutoPackOpener_OpenPack(InteractableAutoPackOpener __instance)
		{
			PackProcessing.PackFromMachine = true;
			if (__instance.m_StoredItemList.Count > 1 || __instance.m_CompactCardDataAmountList.Count > 0)
			{
				PackProcessing.ReturnEligible = true;
				PackProcessing.PackToReturn.Clear();
			}
		}

		[HarmonyPatch(typeof(InteractableAutoPackOpener), "OpenPack")]
		[HarmonyPostfix]
		public static void InteractableAutoPackOpener_OpenPackPost(InteractableAutoPackOpener __instance)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			PackProcessing.PackFromMachine = false;
			PackProcessing.ReturnEligible = false;
			if (PackProcessing.PackToReturn.Count > 0)
			{
				Logger.LogDebug($"Returning pack of value {((IEnumerable<CardData>)PackProcessing.PackToReturn).Sum((Func<CardData, float>)CPlayerData.GetCardMarketPrice)} [Type: {InventoryBase.ItemTypeToCollectionPackType(__instance.GetStoredItemList().First().m_ItemType)}]");
				__instance.m_PackOpenedCount--;
				MachineQueue queue = StoredPackData.Instance.GetOrAddMachine(__instance).Queue;
				EItemType itemType = __instance.GetStoredItemList().First().m_ItemType;
				ECollectionPackType key = InventoryBase.ItemTypeToCollectionPackType(itemType);
				if (!queue.QueuedPacks.ContainsKey(key))
				{
					queue.QueuedPacks[key] = new List<List<CardData>>();
				}
				queue.QueuedPacks[key].Add(PackProcessing.PackToReturn.ToList());
				queue.QueuedItems.Add(itemType);
				PackProcessing.PackToReturn.Clear();
			}
		}

		[HarmonyPatch(typeof(InteractableAutoPackOpener), "OnMouseButtonUp")]
		[HarmonyPrefix]
		public static void InteractableAutoPackOpener_OnMouseButtonUp(InteractableAutoPackOpener __instance)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PackProcessing.CurrentMachine != (Object)null)
			{
				return;
			}
			PackProcessing.CurrentMachine = __instance;
			MachineQueue queue = StoredPackData.Instance.GetOrAddMachine(__instance).Queue;
			if (queue.QueuedItems.Count <= 0)
			{
				PackProcessing.CurrentMachine = null;
				return;
			}
			using (List<EItemType>.Enumerator enumerator = queue.QueuedItems.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ItemUtils.GiveItemToPlayer(enumerator.Current, offset: ((Component)__instance).transform.forward * 0.4f + Vector3.up * 0.5f, parent: ((Component)__instance).transform);
				}
			}
			queue.QueuedItems.Clear();
		}

		[HarmonyPatch(typeof(InteractableAutoPackOpener), "Update")]
		[HarmonyPostfix]
		public static void InteractableAutoPackOpener_Update(InteractableAutoPackOpener __instance)
		{
			if (Settings.Instance.DisplayReturnedAmount.Value)
			{
				if (((InteractableObject)__instance).m_IsBoxedUp)
				{
					return;
				}
				MachineQueue queue = StoredPackData.Instance.GetOrAddMachine(__instance).Queue;
				TextMeshProUGUI componentInChildren = __instance.m_AutoCardOpenerUI.m_DoneGrp.GetComponentInChildren<TextMeshProUGUI>();
				TextMeshProUGUI processingTimeLeft = __instance.m_AutoCardOpenerUI.m_ProcessingTimeLeft;
				if (!((TMP_Text)componentInChildren).text.EndsWith($"\n[{queue.QueuedItems.Count} returned]"))
				{
					if (((TMP_Text)componentInChildren).text.EndsWith("]"))
					{
						((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text.Substring(0, ((TMP_Text)componentInChildren).text.LastIndexOf('[') - 1).TrimEnd();
					}
					((TMP_Text)componentInChildren).text = ((TMP_Text)componentInChildren).text + $"\n[{queue.QueuedItems.Count} returned]";
				}
				if (!((TMP_Text)processingTimeLeft).text.EndsWith($"\n[{queue.QueuedItems.Count} returned]"))
				{
					if (((TMP_Text)processingTimeLeft).text.EndsWith("]"))
					{
						((TMP_Text)processingTimeLeft).text = ((TMP_Text)processingTimeLeft).text.Substring(0, ((TMP_Text)processingTimeLeft).text.LastIndexOf('[') - 1).TrimEnd();
					}
					((TMP_Text)processingTimeLeft).text = ((TMP_Text)processingTimeLeft).text + $"\n[{queue.QueuedItems.Count} returned]";
				}
			}
			else
			{
				TextMeshProUGUI componentInChildren2 = __instance.m_AutoCardOpenerUI.m_DoneGrp.GetComponentInChildren<TextMeshProUGUI>();
				TextMeshProUGUI processingTimeLeft2 = __instance.m_AutoCardOpenerUI.m_ProcessingTimeLeft;
				if (((TMP_Text)componentInChildren2).text.EndsWith("]"))
				{
					((TMP_Text)componentInChildren2).text = ((TMP_Text)componentInChildren2).text.Substring(0, ((TMP_Text)componentInChildren2).text.LastIndexOf('[') - 1).TrimEnd();
				}
				if (((TMP_Text)processingTimeLeft2).text.EndsWith("]"))
				{
					((TMP_Text)processingTimeLeft2).text = ((TMP_Text)processingTimeLeft2).text.Substring(0, ((TMP_Text)processingTimeLeft2).text.LastIndexOf('[') - 1).TrimEnd();
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class SaveDataPatches
	{
		[HarmonyPatch(typeof(CGameManager), "SaveGameData")]
		[HarmonyPostfix]
		public static void CGameManager_SaveGameData(int saveSlotIndex)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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)
			try
			{
				string path = Application.persistentDataPath + $"/modSave_BetterPackOpener{saveSlotIndex}.json";
				if (File.Exists(path))
				{
					File.Delete(path);
				}
				foreach (KeyValuePair<MachineRef, MachineQueue> machineQueue in StoredPackData.Instance.Machines)
				{
					foreach (ECollectionPackType item in from key in machineQueue.Value.QueuedPacks.Keys.ToList()
						where machineQueue.Value.QueuedPacks[key].Count <= 0
						select key)
					{
						machineQueue.Value.QueuedPacks.Remove(item);
					}
				}
				string contents = JsonConvert.SerializeObject((object)StoredPackData.Instance.Machines.Where((KeyValuePair<MachineRef, MachineQueue> m) => (Object)(object)m.Key.Machine != (Object)null && !((InteractableObject)m.Key.Machine).m_IsBoxedUp).ToDictionary((KeyValuePair<MachineRef, MachineQueue> kvp) => kvp.Key.PositionString, (KeyValuePair<MachineRef, MachineQueue> kvp) => kvp.Value), (Formatting)0);
				File.WriteAllText(path, contents);
			}
			catch (Exception arg)
			{
				Logger.LogError($"Failed to save machine queue data: {arg}");
			}
		}

		[HarmonyPatch(typeof(CGameManager), "LoadData")]
		[HarmonyPostfix]
		public static void CGameManager_LoadData(CGameManager __instance)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int currentSaveLoadSlotSelectedIndex = __instance.m_CurrentSaveLoadSlotSelectedIndex;
				string path = Application.persistentDataPath + $"/modSave_BetterPackOpener{currentSaveLoadSlotSelectedIndex}.json";
				StoredPackData.Instance.Machines.Clear();
				PackProcessing.CurrentMachine = null;
				PackProcessing.PackToReturn.Clear();
				PackProcessing.ReturnEligible = false;
				if (!File.Exists(path))
				{
					return;
				}
				for (int i = 0; i < CSingleton<ShelfManager>.Instance.m_SpawnedAutoPackOpenerList.Count; i++)
				{
					InteractableAutoPackOpener machine = CSingleton<ShelfManager>.Instance.m_SpawnedAutoPackOpenerList[i];
					if (!CSingleton<ShelfManager>.Instance.m_AutoPackOpenerSaveDataList[i].isBoxed)
					{
						StoredPackData.Instance.Machines[new MachineRef(machine)] = new MachineQueue();
					}
				}
				foreach (KeyValuePair<string, MachineQueue> item in JsonConvert.DeserializeObject<Dictionary<string, MachineQueue>>(File.ReadAllText(path)))
				{
					Vector3 val = item.Key.StringToVector();
					MachineRef machineAtPos = StoredPackData.Instance.GetMachineAtPos(val);
					if (machineAtPos != null)
					{
						StoredPackData.Instance.Machines[machineAtPos] = item.Value;
					}
					else
					{
						Logger.LogWarning($"Failed to load machine at position {val}: No matching machine found.");
					}
				}
			}
			catch (Exception arg)
			{
				Logger.LogError($"Failed to load machine queue data: {arg}");
			}
		}
	}
}
namespace TCGShopBetterPackOpener.Logging
{
	public class Logger
	{
		public static void LogInfo(string message)
		{
			Plugin.Log.LogInfo((object)message);
		}

		public static void LogWarning(string message)
		{
			Plugin.Log.LogWarning((object)message);
		}

		public static void LogError(string message)
		{
			Plugin.Log.LogError((object)message);
		}

		public static void LogDebug(string message)
		{
			Plugin.Log.LogDebug((object)message);
		}

		public static void LogFatal(string message)
		{
			Plugin.Log.LogFatal((object)message);
		}
	}
}
namespace TCGShopBetterPackOpener.Globals
{
	public class NFP
	{
		public static readonly NumberFormatInfo Default = new NumberFormatInfo
		{
			NumberDecimalSeparator = "."
		};
	}
}
namespace TCGShopBetterPackOpener.Extensions
{
	public static class StringExtensions
	{
		public static Vector3 StringToVector(this string vectorString)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			string[] array = vectorString.Split(' ');
			if (array.Length != 3)
			{
				throw new FormatException("Invalid vector string format: " + vectorString);
			}
			return new Vector3(float.Parse(array[0], NFP.Default), float.Parse(array[1], NFP.Default), float.Parse(array[2], NFP.Default));
		}
	}
	public static class Vector3Extensions
	{
		public static string FormattedString(this Vector3 vector)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return string.Format(NFP.Default, "{0} {1} {2}", vector.x, vector.y, vector.z);
		}
	}
}
namespace TCGShopBetterPackOpener.Config
{
	public class Settings
	{
		public ConfigEntry<bool> Enabled;

		public ConfigEntry<float> ReturnThreshold;

		public ConfigEntry<string> AlwaysReturnFilter;

		public ConfigEntry<bool> DisplayReturnedAmount;

		public ConfigEntry<KeyboardShortcut> DebugKeybind;

		public static Settings Instance { get; private set; } = new Settings();

		public void Init(ConfigFile config)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			Enabled = config.Bind<bool>("General", "Enabled", true, "Whether this mod is enabled or not.");
			ReturnThreshold = config.Bind<float>("Filters", "ReturnThreshold", 100f, new ConfigDescription("If the total market value of a pack is equal to or above this value, the pack opening machines will return it. This value is in dollars. Refer to the README for conversion rates for other currencies.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 100000f), Array.Empty<object>()));
			AlwaysReturnFilter = config.Bind<string>("Filters", "AlwaysReturnFilter", "", new ConfigDescription("A comma-separated list of card keyword groups that will always have packs containing its cards returned by the pack opening machines, regardless of their value. See the README for a list of keywords. For example, 'ghost,foil fullart,god ex+' will return any pack that contains any Ghost expansion card, a Foil Full Art border card, or a God Pack with all EX or higher border cards. Leave empty to disable this filter.", (AcceptableValueBase)null, Array.Empty<object>()));
			DisplayReturnedAmount = config.Bind<bool>("General", "DisplayReturnedAmount", true, "Whether pack opening machines will display the amount of packs queued to be returned to the player.");
			DebugKeybind = config.Bind<KeyboardShortcut>("Debug", "DebugKeybind", new KeyboardShortcut((KeyCode)283, Array.Empty<KeyCode>()), "The keybind to toggle the debug GUI.");
		}
	}
}
namespace TCGShopBetterPackOpener.Cards
{
	public static class CardFilter
	{
		private static readonly List<string> RequiredKeywords = new List<string>
		{
			"ghost", "firstedition", "silver", "gold", "ex", "fullart", "borderless", "foil", "god", "firstedition+",
			"silver+", "gold+", "ex+", "fullart+", "borderless+"
		};

		public static bool FilterPack(List<CardData> cardDataList)
		{
			if (cardDataList.Count <= 0)
			{
				return false;
			}
			string text = CardUtils.CardsToString(cardDataList);
			string text2 = CardUtils.CardsToShortString(cardDataList);
			float num = ((IEnumerable<CardData>)cardDataList).Sum((Func<CardData, float>)CPlayerData.GetCardMarketPrice);
			if (num >= Settings.Instance.ReturnThreshold.Value)
			{
				Logger.LogDebug($"Pack value {num} above {Settings.Instance.ReturnThreshold.Value}, returning pack with {text2}.");
				Plugin.ProcessedLog.Add($"MATCH: {text} (value > {Settings.Instance.ReturnThreshold.Value})");
				return true;
			}
			List<List<string>> keywords = cardDataList.Select(CardUtils.GetCardKeywords).ToList();
			if (Match(cardDataList, keywords, (from f in Settings.Instance.AlwaysReturnFilter.Value.Split(',')
				select f.Trim().ToLower().Replace("-", "")
					.Replace("_", "") into f
				where !string.IsNullOrEmpty(f) && IsValid(f)
				select f.Split(" ").ToList()).ToList(), out var match))
			{
				Logger.LogDebug("Pack matches the filter [" + match + "], returning pack with " + text2 + ".");
				Plugin.ProcessedLog.Add("MATCH: " + text + " (AlwaysReturnFilter: " + match + ")");
				return true;
			}
			Logger.LogDebug("Pack does not meet criteria: " + text2);
			return false;
		}

		private static bool Match(List<CardData> cards, List<List<string>> keywords, List<List<string>> filters, out string match)
		{
			foreach (List<string> filter in filters)
			{
				if (filter.Count == 0)
				{
					continue;
				}
				List<string> values = filter.ToList();
				if (filter.Contains("god"))
				{
					filter.Remove("god");
					if (filter.Count == 0)
					{
						if (cards.All((CardData c) => (int)c.expansionType == 2) || cards.All((CardData c) => c.isFoil) || cards.All((CardData c) => c.borderType == cards.First().borderType && (int)cards.First().borderType > 0))
						{
							match = string.Join(" ", values);
							return true;
						}
					}
					else if (keywords.All((List<string> k) => filter.All(k.Contains)))
					{
						match = string.Join(" ", values);
						return true;
					}
				}
				else if (keywords.Any((List<string> k) => filter.All(k.Contains)))
				{
					match = string.Join(" ", values);
					return true;
				}
			}
			match = null;
			return false;
		}

		private static bool IsValid(string filter)
		{
			return filter.Split(' ').Any((string f) => RequiredKeywords.Contains(f));
		}
	}
}