Decompiled source of CardChoiceSpawnUniqueCardPatch v0.1.10

CardChoiceSpawnUniqueCardPatch.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using CardChoiceSpawnUniqueCardPatch.CustomCategories;
using HarmonyLib;
using ModdingUtils.Utils;
using UnboundLib.Cards;
using UnboundLib.Utils;
using UnityEngine;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CardChoiceSpawnUniqueCardPatch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CardChoiceSpawnUniqueCardPatch")]
[assembly: AssemblyTitle("CardChoiceSpawnUniqueCardPatch")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CardChoiceSpawnUniqueCardPatch
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("pykess.rounds.plugins.cardchoicespawnuniquecardpatch", "CardChoiceSpawnUniqueCardPatch", "0.1.10")]
	[BepInProcess("Rounds.exe")]
	public class CardChoiceSpawnUniqueCardPatch : BaseUnityPlugin
	{
		private const string ModId = "pykess.rounds.plugins.cardchoicespawnuniquecardpatch";

		private const string ModName = "CardChoiceSpawnUniqueCardPatch";

		internal static CardInfo NullCard;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("pykess.rounds.plugins.cardchoicespawnuniquecardpatch").PatchAll();
			CustomCardCategories instance = CustomCardCategories.instance;
		}

		private void Start()
		{
			CustomCard.BuildCard<NullCard>((Action<CardInfo>)delegate(CardInfo cardInfo)
			{
				NullCard = cardInfo;
			});
		}
	}
	[Serializable]
	[HarmonyPatch(typeof(CardChoice), "SpawnUniqueCard")]
	internal class CardChoicePatchSpawnUniqueCard
	{
		private static bool Prefix(ref GameObject __result, CardChoice __instance, Vector3 pos, Quaternion rot)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			Player val = (((int)(PickerType)Traverse.Create((object)__instance).Field("pickerType").GetValue() != 0) ? PlayerManager.instance.players[__instance.pickrID] : PlayerManager.instance.GetPlayersInTeam(__instance.pickrID)[0]);
			CardInfo val2 = null;
			if (CardChoice.instance.cards.Length != 0)
			{
				val2 = Cards.instance.GetRandomCardWithCondition(val, (Gun)null, (GunAmmo)null, (CharacterData)null, (HealthHandler)null, (Gravity)null, (Block)null, (CharacterStatModifiers)null, GetCondition(__instance), 1000);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				GameObject val3 = (GameObject)typeof(CardChoice).InvokeMember("Spawn", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[3]
				{
					((Component)val2).gameObject,
					pos,
					rot
				});
				val3.GetComponent<CardInfo>().sourceCard = ((Component)val2).GetComponent<CardInfo>();
				((Behaviour)((Component)val3.GetComponentInChildren<DamagableEvent>()).GetComponent<Collider2D>()).enabled = false;
				__result = val3;
			}
			else
			{
				GameObject val4 = (GameObject)typeof(CardChoice).InvokeMember("Spawn", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, __instance, new object[3]
				{
					((Component)CardChoiceSpawnUniqueCardPatch.NullCard).gameObject,
					pos,
					rot
				});
				val4.GetComponent<CardInfo>().sourceCard = ((Component)CardChoiceSpawnUniqueCardPatch.NullCard).GetComponent<CardInfo>();
				((Behaviour)((Component)val4.GetComponentInChildren<DamagableEvent>()).GetComponent<Collider2D>()).enabled = false;
				__result = val4;
			}
			return false;
		}

		private static Func<CardInfo, Player, Gun, GunAmmo, CharacterData, HealthHandler, Gravity, Block, CharacterStatModifiers, bool> GetCondition(CardChoice instance)
		{
			return (CardInfo card, Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers stats) => CorrectedCondition(instance)(card, player) && ModifiedBaseCondition(instance)(card, player);
		}

		private static Func<CardInfo, Player, bool> CorrectedCondition(CardChoice instance)
		{
			return (CardInfo card, Player player) => Cards.instance.PlayerIsAllowedCard(player, card);
		}

		private static Func<CardInfo, Player, bool> ModifiedBaseCondition(CardChoice instance)
		{
			return delegate(CardInfo card, Player player)
			{
				List<GameObject> source = (List<GameObject>)Traverse.Create((object)instance).Field("spawnedCards").GetValue();
				if (instance.pickrID != -1)
				{
					Holdable holdable = ((Component)player.data).GetComponent<Holding>().holdable;
					if (Object.op_Implicit((Object)(object)holdable))
					{
						Gun component = ((Component)holdable).GetComponent<Gun>();
						Gun component2 = ((Component)card).GetComponent<Gun>();
						if (Object.op_Implicit((Object)(object)component2) && Object.op_Implicit((Object)(object)component) && component2.lockGunToDefault && component.lockGunToDefault)
						{
							return false;
						}
					}
				}
				return card.categories.Contains(CustomCardCategories.CanDrawMultipleCategory) || !source.Any((GameObject spawnedCard) => ((Object)spawnedCard).name.Replace("(Clone)", "") == ((Object)((Component)card).gameObject).name);
			};
		}
	}
	public class NullCard : CustomCard
	{
		public const string cardName = "  ";

		public override void SetupCard(CardInfo cardInfo, Gun gun, ApplyCardStats cardStats, CharacterStatModifiers statModifiers)
		{
			cardInfo.sourceCard = CardChoiceSpawnUniqueCardPatch.NullCard;
			cardInfo.categories = cardInfo.categories.ToList().Concat(new List<CardCategory> { CustomCardCategories.CanDrawMultipleCategory }).ToArray();
		}

		public override void OnAddCard(Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers characterStats)
		{
			((Component)this).gameObject.GetComponent<CardInfo>().sourceCard = CardChoiceSpawnUniqueCardPatch.NullCard;
		}

		public override void OnRemoveCard()
		{
		}

		protected override string GetTitle()
		{
			return "  ";
		}

		protected override string GetDescription()
		{
			return "";
		}

		protected override GameObject GetCardArt()
		{
			return null;
		}

		protected override Rarity GetRarity()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return (Rarity)0;
		}

		protected override CardInfoStat[] GetStats()
		{
			return null;
		}

		protected override CardThemeColorType GetTheme()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return (CardThemeColorType)3;
		}

		public override bool GetEnabled()
		{
			return false;
		}

		public override string GetModName()
		{
			return "NULL";
		}
	}
}
namespace CardChoiceSpawnUniqueCardPatch.CustomCategories
{
	public class CustomCardCategories
	{
		public static readonly CustomCardCategories instance = new CustomCardCategories();

		private List<CardCategory> cardCategories = new List<CardCategory>();

		public static CardCategory CanDrawMultipleCategory => instance.CardCategory("__CanDrawMultiple__");

		private CustomCardCategories()
		{
			CardInfo[] array = (from obj in Resources.LoadAll<GameObject>("0 Cards/")
				where Object.op_Implicit((Object)(object)obj.GetComponent<CardInfo>())
				select obj into obj2
				select obj2.GetComponent<CardInfo>()).ToArray();
			CardInfo[] array2 = array;
			foreach (CardInfo card in array2)
			{
				UpdateAndPullCategoriesFromCard(card);
			}
			foreach (CardInfo item in CardManager.cards.Values.Select((Card c) => c.cardInfo))
			{
				UpdateAndPullCategoriesFromCard(item);
			}
			CardManager.AddAllCardsCallback((Action<CardInfo[]>)FirstStartAction);
		}

		private void FirstStartAction(CardInfo[] cards)
		{
			foreach (CardInfo card in cards)
			{
				UpdateAndPullCategoriesFromCard(card);
			}
		}

		public CardCategory[] GetCategoriesFromCard(CardInfo card)
		{
			return card.categories;
		}

		public CardCategory[] GetBlacklistedCategoriesFromCard(CardInfo card)
		{
			return card.blacklistedCategories;
		}

		public void UpdateAndPullCategoriesFromCard(CardInfo card)
		{
			List<CardCategory> list = new List<CardCategory>();
			for (int i = 0; i < card.categories.Length; i++)
			{
				CardCategory val = card.categories[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (!cardCategories.Contains(val))
				{
					CardCategory categoryWithName = GetCategoryWithName(((Object)val).name);
					if ((Object)(object)categoryWithName != (Object)null)
					{
						card.categories[i] = categoryWithName;
						val = card.categories[i];
					}
					else
					{
						cardCategories.Add(val);
					}
				}
				list.Add(val);
			}
			card.categories = list.ToArray();
			list = new List<CardCategory>();
			for (int j = 0; j < card.blacklistedCategories.Length; j++)
			{
				CardCategory val2 = card.blacklistedCategories[j];
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				if (!cardCategories.Contains(val2))
				{
					CardCategory categoryWithName2 = GetCategoryWithName(((Object)val2).name);
					if ((Object)(object)categoryWithName2 != (Object)null)
					{
						card.blacklistedCategories[j] = categoryWithName2;
						val2 = card.blacklistedCategories[j];
					}
					else
					{
						cardCategories.Add(val2);
					}
				}
				list.Add(val2);
			}
			card.blacklistedCategories = list.ToArray();
		}

		public CardInfo[] GetActiveCardsFromCategory(CardCategory cardCategory)
		{
			return Cards.instance.GetAllCardsWithCondition(((ObservableCollection<CardInfo>)typeof(CardManager).GetField("activeCards", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)).ToArray(), (Player)null, (Func<CardInfo, Player, bool>)((CardInfo card, Player player) => card.categories.Intersect((IEnumerable<CardCategory>)(object)new CardCategory[1] { cardCategory }).Any()));
		}

		public CardInfo[] GetInactiveCardsFromCategory(CardCategory cardCategory)
		{
			return Cards.instance.GetAllCardsWithCondition(((List<CardInfo>)typeof(CardManager).GetField("inactiveCards", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)).ToArray(), (Player)null, (Func<CardInfo, Player, bool>)((CardInfo card, Player player) => card.categories.Intersect((IEnumerable<CardCategory>)(object)new CardCategory[1] { cardCategory }).Any()));
		}

		public CardInfo[] GetAllCardsFromCategory(CardCategory cardCategory)
		{
			return GetActiveCardsFromCategory(cardCategory).Concat(GetInactiveCardsFromCategory(cardCategory)).ToArray();
		}

		private CardCategory GetCategoryWithName(string categoryName)
		{
			foreach (CardCategory cardCategory in cardCategories)
			{
				if ((Object)(object)cardCategory != (Object)null && ((Object)cardCategory).name != null && ((Object)cardCategory).name.ToLower() == categoryName.ToLower())
				{
					return cardCategory;
				}
			}
			return null;
		}

		public CardCategory CardCategory(string categoryName)
		{
			CardCategory val = GetCategoryWithName(categoryName);
			if ((Object)(object)val == (Object)null)
			{
				CardCategory val2 = ScriptableObject.CreateInstance<CardCategory>();
				((Object)val2).name = categoryName.ToLower();
				cardCategories.Add(val2);
				val = val2;
			}
			return val;
		}

		public void MakeCardsExclusive(CardInfo card1, CardInfo card2)
		{
			string categoryName = "__" + ((Object)card1).name + "_" + ((Object)card2).name + "_EXCLUSIVE__";
			string categoryName2 = "__" + ((Object)card2).name + "_" + ((Object)card1).name + "_EXCLUSIVE__";
			CardCategory val = CardCategory(categoryName);
			CardCategory val2 = CardCategory(categoryName2);
			card1.categories = card1.categories.Concat((IEnumerable<CardCategory>)(object)new CardCategory[1] { val }).ToArray();
			card2.categories = card2.categories.Concat((IEnumerable<CardCategory>)(object)new CardCategory[1] { val2 }).ToArray();
			card1.blacklistedCategories = card1.blacklistedCategories.Concat((IEnumerable<CardCategory>)(object)new CardCategory[1] { val2 }).ToArray();
			card2.blacklistedCategories = card2.blacklistedCategories.Concat((IEnumerable<CardCategory>)(object)new CardCategory[1] { val }).ToArray();
		}
	}
}