Decompiled source of My Little Pony FIM Card Pack v2.0.1

MLP_Sigils.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Card;
using Pixelplacement;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MLP_Sigils")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Sigils for the My Little Pony Cardpack.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MLP_Sigils")]
[assembly: AssemblyTitle("MLP_Sigils")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MLP_Sigils;

[HarmonyPatch]
public class BoardSetAndCleanUp
{
	[HarmonyPatch(typeof(TurnManager), "CleanupPhase")]
	[HarmonyPostfix]
	public static void CleanupPhasePostFix()
	{
		foreach (Tuple<GameObject, Surprise, int> item in Surprise.DisappearedCards.Keys.ToList())
		{
			Object.Destroy((Object)(object)item.Item1);
		}
		Surprise.DisappearedCards.Clear();
	}

	[HarmonyPatch(typeof(TurnManager), "SetupPhase")]
	[HarmonyPostfix]
	public static void SetupPhasePostFix()
	{
		foreach (Tuple<GameObject, Surprise, int> item in Surprise.DisappearedCards.Keys.ToList())
		{
			Object.Destroy((Object)(object)item.Item1);
		}
		Surprise.DisappearedCards.Clear();
	}
}
[HarmonyPatch(typeof(TurnManager), "DoUpkeepPhase")]
public class OnUpkeep
{
	[HarmonyPrefix]
	public static void Prefix(bool playerUpkeep)
	{
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		if (!playerUpkeep)
		{
			return;
		}
		foreach (Tuple<GameObject, Surprise, int> item in Surprise.DisappearedCards.Keys.ToList())
		{
			Surprise.DisappearedCards[item]++;
			if (Surprise.DisappearedCards[item] == item.Item3)
			{
				PlayableCard component = item.Item1.GetComponent<PlayableCard>();
				List<CardSlot> list = (component.OpponentCard ? Singleton<BoardManager>.Instance.opponentSlots : Singleton<BoardManager>.Instance.playerSlots);
				List<CardSlot> list2 = list.Where((CardSlot x) => (Object)(object)x.Card == (Object)null).ToList();
				Random random = new Random();
				CardSlot val = ((list2.Count <= 0) ? list[random.Next(list.Count)] : list2[random.Next(list2.Count)]);
				if ((Object)(object)val.Card != (Object)null)
				{
					((Card)val.Card).ExitBoard(0f, new Vector3(0f, 0f, 0f));
				}
				((Component)component).transform.position = ((Component)val).transform.position + Vector3.up * 0.025f;
				((Component)component).transform.rotation = ((Component)val).transform.GetChild(0).rotation;
				component.Slot = val;
				val.Card = component;
				item.Item2.AttackCount = Surprise.DisappearedCards[item];
				Surprise.DisappearedCards.Remove(item);
			}
		}
	}
}
[BepInPlugin("MLP_Sigils", "MLP Sigils", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "MLP_Sigils";

	private const string PluginName = "MLP Sigils";

	private const string PluginVersion = "1.0.0";

	public static string Directory;

	internal static ManualLogSource Log;

	public void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded MLP Sigils mod! - Made by Lily");
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("MLP_Sigils");
		val.PatchAll();
		AddSurprise();
		AddDevStuff();
	}

	private void AddDevStuff()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected I4, but got Unknown
		CardInfo val = CardExtensions.CardByName((IEnumerable<CardInfo>)CardManager.BaseGameCards, "Stoat_Talking");
		CardExtensions.AddSpecialAbilities(val, (SpecialTriggeredAbility[])(object)new SpecialTriggeredAbility[1] { (SpecialTriggeredAbility)(int)Surprise.ability });
	}

	public Texture2D GetTexture(string path)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		byte[] array = File.ReadAllBytes(Path.Combine(((BaseUnityPlugin)this).Info.Location.Replace("MLP_Sigils.dll", ""), "Artwork/" + path));
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, array);
		((Texture)val).filterMode = (FilterMode)0;
		return val;
	}

	public void AddSurprise()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		Surprise.ability = SpecialTriggeredAbilityManager.Add("MLP_Sigils", "Surprise", typeof(Surprise)).Id;
	}
}
public class Surprise : SpecialCardBehaviour
{
	public static SpecialTriggeredAbility ability;

	public static Dictionary<Tuple<GameObject, Surprise, int>, int> DisappearedCards = new Dictionary<Tuple<GameObject, Surprise, int>, int>();

	public int TurnsInPlay = 0;

	public int TurnsUntilDisappearance;

	public int? AttackCount = null;

	public static List<string> SurpriseLines = new List<string> { "[e:1]Miss me?!?", "[e:4]Suuurprise!!!!", "I like this game!", "Don't forget about me!" };

	public void Start()
	{
		Random random = new Random();
		TurnsUntilDisappearance = random.Next(2, 6);
	}

	public override bool RespondsToUpkeep(bool playerUpkeep)
	{
		return playerUpkeep;
	}

	public override IEnumerator OnUpkeep(bool playerUpkeep)
	{
		TurnsInPlay++;
		if (TurnsInPlay == TurnsUntilDisappearance)
		{
			Random random = new Random();
			DisappearedCards[new Tuple<GameObject, Surprise, int>(((Component)this).gameObject, this, random.Next(2, 5))] = 0;
			((SpecialCardBehaviour)this).PlayableCard.UnassignFromSlot();
			Transform transform = ((Component)this).gameObject.transform;
			transform.position += Vector3.up * -10f;
		}
		if (AttackCount.HasValue)
		{
			yield return AttackSlotXTimes(((SpecialCardBehaviour)this).PlayableCard, AttackCount.Value);
			AttackCount = null;
		}
	}

	public static IEnumerator AttackSlotXTimes(PlayableCard card, int count)
	{
		yield return (object)new WaitForSeconds(0.1f);
		Singleton<ViewManager>.Instance.SwitchToView((View)4, true, false);
		yield return (object)new WaitForSeconds(0.1f);
		TalkingCard TalkingComponent = ((Component)card).GetComponent<TalkingCard>();
		if ((Object)(object)TalkingComponent != (Object)null)
		{
			Random random = new Random();
			Line line = new Line
			{
				text = SurpriseLines[random.Next(SurpriseLines.Count)]
			};
			yield return TalkingComponent.PlayLine(line);
		}
		yield return (object)new WaitForSeconds(0.2f);
		FakeCombatHandler.FakeCombatThing fakecombat = new FakeCombatHandler.FakeCombatThing();
		for (int i = 0; i < count; i++)
		{
			yield return fakecombat.FakeCombat(!card.OpponentCard, null, card.Slot);
			yield return (object)new WaitForSeconds(0.1f);
		}
		yield return (object)new WaitForSeconds(0.1f);
		Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)0;
	}
}
public class FakeCombatHandler
{
	public class FakeCombatThing
	{
		public static Ability ability;

		public static bool isCombatPhase;

		public int DamageDealtThisPhase { get; private set; }

		public IEnumerator FakeCombat(bool playerIsAttacker, SpecialBattleSequencer specialSequencer, CardSlot attacker, List<CardSlot> overrideTargets = null, int overrideDMG = -1)
		{
			DamageDealtThisPhase = 0;
			yield return SlotAttackSequence(attacker, overrideTargets, overrideDMG);
			if (DamageDealtThisPhase > 0 && !isCombatPhase)
			{
				yield return (object)new WaitForSeconds(0.4f);
				int excessDamage = 0;
				if (playerIsAttacker)
				{
					excessDamage = Singleton<LifeManager>.Instance.Balance + DamageDealtThisPhase - 5;
					excessDamage = Mathf.Max(0, excessDamage);
				}
				int damage = DamageDealtThisPhase - excessDamage;
				if (DamageDealtThisPhase >= 666)
				{
					AchievementManager.Unlock((Achievement)25);
				}
				if ((Object)(object)specialSequencer == (Object)null || !specialSequencer.PreventDamageAddedToScales)
				{
					yield return Singleton<LifeManager>.Instance.ShowDamageSequence(damage, damage, !playerIsAttacker, 0f, (GameObject)null, 0f, true);
				}
				if ((Object)(object)specialSequencer != (Object)null)
				{
					yield return specialSequencer.DamageAddedToScale(damage + excessDamage, playerIsAttacker);
				}
				if ((!((Object)(object)specialSequencer != (Object)null) || !specialSequencer.PreventDamageAddedToScales) && excessDamage > 0 && Singleton<TurnManager>.Instance.Opponent.NumLives == 1 && Singleton<TurnManager>.Instance.Opponent.GiveCurrencyOnDefeat)
				{
					yield return Singleton<TurnManager>.Instance.Opponent.TryRevokeSurrender();
					RunState run = RunState.Run;
					run.currency += excessDamage;
				}
				Singleton<ViewManager>.Instance.Controller.LockState = (ViewLockState)0;
				DamageDealtThisPhase = 0;
			}
		}

		public IEnumerator SlotAttackSlot(CardSlot attackingSlot, CardSlot opposingSlot, float waitAfter = 0f, int overrideDMG = -1)
		{
			yield return Singleton<GlobalTriggerHandler>.Instance.TriggerCardsOnBoard((Trigger)6, false, new object[2] { opposingSlot, attackingSlot.Card });
			yield return (object)new WaitForSeconds(0.025f);
			if (!((Object)(object)attackingSlot.Card != (Object)null))
			{
				yield break;
			}
			if (((Card)attackingSlot.Card).Anim.DoingAttackAnimation)
			{
				yield return (object)new WaitUntil((Func<bool>)(() => !((Card)attackingSlot.Card).Anim.DoingAttackAnimation));
				yield return (object)new WaitForSeconds(0.25f);
			}
			if ((Object)(object)opposingSlot.Card != (Object)null && attackingSlot.Card.AttackIsBlocked(opposingSlot))
			{
				ProgressionData.SetAbilityLearned((Ability)21);
				yield return Singleton<CombatPhaseManager>.Instance.ShowCardBlocked(attackingSlot.Card);
			}
			else if (attackingSlot.Card.CanAttackDirectly(opposingSlot))
			{
				DamageDealtThisPhase += ((overrideDMG > -1) ? overrideDMG : attackingSlot.Card.Attack);
				yield return Singleton<CombatPhaseManager>.Instance.VisualizeCardAttackingDirectly(attackingSlot, opposingSlot, 0);
				if (attackingSlot.Card.TriggerHandler.RespondsToTrigger((Trigger)20, new object[1] { (overrideDMG > -1) ? overrideDMG : attackingSlot.Card.Attack }))
				{
					yield return attackingSlot.Card.TriggerHandler.OnTrigger((Trigger)20, new object[1] { (overrideDMG > -1) ? overrideDMG : attackingSlot.Card.Attack });
				}
			}
			else
			{
				float heightOffset = (((Object)(object)opposingSlot.Card == (Object)null) ? 0f : opposingSlot.Card.SlotHeightOffset);
				if (heightOffset > 0f)
				{
					Tween.Position(((Component)attackingSlot.Card).transform, ((Component)attackingSlot.Card).transform.position + Vector3.up * heightOffset, 0.05f, 0f, Tween.EaseInOut, (LoopType)0, (Action)null, (Action)null, true);
				}
				((Card)attackingSlot.Card).Anim.PlayAttackAnimation(attackingSlot.Card.IsFlyingAttackingReach(), opposingSlot, (Action)null);
				yield return (object)new WaitForSeconds(0.07f);
				((Card)attackingSlot.Card).Anim.SetAnimationPaused(true);
				PlayableCard attackingCard = attackingSlot.Card;
				yield return Singleton<GlobalTriggerHandler>.Instance.TriggerCardsOnBoard((Trigger)7, false, new object[1] { opposingSlot.Card });
				if ((Object)(object)attackingCard != (Object)null && (Object)(object)attackingCard.Slot != (Object)null)
				{
					attackingSlot = attackingCard.Slot;
					if (attackingSlot.Card.IsFlyingAttackingReach())
					{
						((Card)opposingSlot.Card).Anim.PlayJumpAnimation();
						yield return (object)new WaitForSeconds(0.3f);
						((Card)attackingSlot.Card).Anim.PlayAttackInAirAnimation();
					}
					((Card)attackingSlot.Card).Anim.SetAnimationPaused(false);
					yield return (object)new WaitForSeconds(0.05f);
					int overkillDamage = ((overrideDMG > -1) ? overrideDMG : (attackingSlot.Card.Attack - opposingSlot.Card.Health));
					yield return opposingSlot.Card.TakeDamage((overrideDMG > -1) ? overrideDMG : attackingSlot.Card.Attack, attackingSlot.Card);
					yield return DealOverkillDamage(overkillDamage, attackingSlot, opposingSlot);
					if ((Object)(object)attackingSlot.Card != (Object)null && heightOffset > 0f)
					{
						yield return Singleton<BoardManager>.Instance.AssignCardToSlot(attackingSlot.Card, attackingSlot.Card.Slot, 0.1f, (Action)null, false);
					}
				}
			}
			yield return (object)new WaitForSeconds(waitAfter);
		}

		private IEnumerator SlotAttackSequence(CardSlot slot, List<CardSlot> overrideTargets = null, int overrideDMG = -1)
		{
			List<CardSlot> opposingSlots = slot.Card.GetOpposingSlots();
			if (overrideTargets != null)
			{
				opposingSlots = overrideTargets;
			}
			Singleton<ViewManager>.Instance.SwitchToView(Singleton<BoardManager>.Instance.CombatView, false, false);
			foreach (CardSlot opposingSlot in opposingSlots)
			{
				Singleton<ViewManager>.Instance.SwitchToView(Singleton<BoardManager>.Instance.CombatView, false, false);
				yield return SlotAttackSlot(slot, opposingSlot, (opposingSlots.Count > 1) ? 0.1f : 0f, overrideDMG);
			}
			Singleton<CombatPhaseManager>.Instance.VisualizeClearSniperAbility();
		}

		protected virtual IEnumerator DealOverkillDamage(int damage, CardSlot attackingSlot, CardSlot opposingSlot)
		{
			if (!((Object)(object)attackingSlot.Card != (Object)null) || !attackingSlot.IsPlayerSlot || damage <= 0)
			{
				yield break;
			}
			PlayableCard queuedCard = Singleton<BoardManager>.Instance.GetCardQueuedForSlot(opposingSlot);
			if ((Object)(object)queuedCard != (Object)null)
			{
				yield return (object)new WaitForSeconds(0.1f);
				Singleton<ViewManager>.Instance.SwitchToView(Singleton<BoardManager>.Instance.QueueView, false, false);
				yield return (object)new WaitForSeconds(0.3f);
				if (queuedCard.HasAbility((Ability)21))
				{
					yield return Singleton<CombatPhaseManager>.Instance.ShowCardBlocked(attackingSlot.Card);
					yield break;
				}
				yield return Singleton<CombatPhaseManager>.Instance.PreOverkillDamage(queuedCard);
				yield return queuedCard.TakeDamage(damage, attackingSlot.Card);
				yield return Singleton<CombatPhaseManager>.Instance.PostOverkillDamage(queuedCard);
			}
		}
	}

	public static IEnumerator DoSimpleFakeCombat(int damage, CardSlot attacker, CardSlot target)
	{
		yield return HandleSimpleFakeCombat(damage, attacker, target);
	}

	private static IEnumerator HandleSimpleFakeCombat(int damage, CardSlot attacker, CardSlot target)
	{
		bool impactFrameReached = false;
		((Card)attacker.Card).Anim.PlayAttackAnimation(false, target, (Action)delegate
		{
			impactFrameReached = true;
		});
		yield return (object)new WaitUntil((Func<bool>)(() => impactFrameReached));
		yield return target.Card.TakeDamage(damage, attacker.Card);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "MLP_Sigils";

	public const string PLUGIN_NAME = "MLP_Sigils";

	public const string PLUGIN_VERSION = "1.0.0";
}