Decompiled source of SuccClan v0.2.1

plugins/mt2_succclan.Plugin.dll

Decompiled a week 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using ShinyShoe;
using TrainworksReloaded.Base;
using TrainworksReloaded.Base.Extensions;
using TrainworksReloaded.Core;
using TrainworksReloaded.Core.Configuration;
using TrainworksReloaded.Core.Extensions;
using UnityEngine;
using UnityEngine.UI;

[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("mt2_succclan.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+189137cecda9de051d7193b6b524232cce9a11de")]
[assembly: AssemblyProduct("mt2_succclan.Plugin")]
[assembly: AssemblyTitle("mt2_succclan.Plugin")]
[assembly: AssemblyVersion("0.2.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 mt2_succclan.Plugin
{
	public sealed class CardEffectPsionicPermanentGrowth : CardEffectAddCardUpgradeToUnits
	{
		public override IEnumerator ApplyEffect(CardEffectState s, CardEffectParams p, ICoreGameManagers c, ISystemManagers m)
		{
			CharacterState selfTarget = p.selfTarget;
			if (!((Object)(object)selfTarget == (Object)null) && !selfTarget.IsDestroyed)
			{
				StatusEffectStackData val = s.GetSourceCardEffectData().GetParamStatusEffects()[0];
				int times = selfTarget.GetStatusEffectStacks(val.statusId) / val.count;
				selfTarget.RemoveStatusEffect(val.statusId, times * val.count, false);
				for (int i = 0; i < times; i++)
				{
					yield return <>n__0(s, p, c, m);
				}
			}
		}

		[CompilerGenerated]
		[DebuggerHidden]
		private IEnumerator <>n__0(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			return ((CardEffectAddCardUpgradeToUnits)this).ApplyEffect(cardEffectState, cardEffectParams, coreGameManagers, sysManagers);
		}
	}
	public sealed class RelicEffectRageOnFrantic : RelicEffectBase
	{
		public override bool CanApplyInPreviewMode => true;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}

		public override void OnCharacterStatusEffectApplied(CharacterState character, StatusEffectState status, ICoreGameManagers core, RelicManager relics, SaveManager save, bool spawnEffect)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			if (!((Object)(object)character == (Object)null) && !character.IsDestroyed && !(status.GetStatusId() != "mt2_succclan.Plugin_frantic"))
			{
				StatusEffectStackData val = ((IEnumerable<StatusEffectStackData>)((RelicEffectBase)this).SourceRelicEffectData.GetParamStatusEffects()).FirstOrDefault((Func<StatusEffectStackData, bool>)((StatusEffectStackData stack) => stack.statusId == "buff"));
				if (val != null)
				{
					character.AddStatusEffect("buff", val.count, new AddStatusEffectParams
					{
						sourceRelicState = ((RelicEffectBase)this).SourceRelicState
					}, (CharacterState)null, true, false, true, false, false);
				}
			}
		}
	}
	public sealed class RelicEffectArmorOnPyreAttacked : RelicEffectBase
	{
		public override bool CanApplyInPreviewMode => true;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}
	}
	[HarmonyPatch(typeof(CharacterState), "ApplyDamage")]
	internal static class PyreAttackedArmorPatch
	{
		private static void Postfix(CharacterState __instance, ApplyDamageParams damageParams, RelicManager ___relicManager, ref IEnumerator __result)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance == (Object)null) && !__instance.IsDestroyed && __instance.IsPyreHeart() && !((Object)(object)damageParams.attacker == (Object)null) && !damageParams.attacker.IsDestroyed && (int)damageParams.attacker.GetTeamType() == 1 && (int)damageParams.damageType == 4)
			{
				__result = ApplyAfter(__result, __instance, ___relicManager);
			}
		}

		private static IEnumerator ApplyAfter(IEnumerator original, CharacterState pyre, RelicManager relics)
		{
			yield return original;
			if ((Object)(object)pyre == (Object)null || pyre.IsDestroyed || !pyre.IsAlive || (Object)(object)relics == (Object)null)
			{
				yield break;
			}
			foreach (RelicEffectArmorOnPyreAttacked relicEffect in relics.GetRelicEffects<RelicEffectArmorOnPyreAttacked>(new List<RelicEffectArmorOnPyreAttacked>()))
			{
				StatusEffectStackData[] paramStatusEffects = ((RelicEffectBase)relicEffect).SourceRelicEffectData.GetParamStatusEffects();
				foreach (StatusEffectStackData val in paramStatusEffects)
				{
					pyre.AddStatusEffect(val.statusId, val.count, new AddStatusEffectParams
					{
						sourceRelicState = ((RelicEffectBase)relicEffect).SourceRelicState,
						overrideImmunity = true
					}, (CharacterState)null, true, false, true, false, false);
				}
			}
		}
	}
	public class CardEffectAddStatusEffectToClones : CardEffectBase
	{
		public override IEnumerator ApplyEffect(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			StatusEffectStackData[] paramStatusEffects = cardEffectState.GetSourceCardEffectData().GetParamStatusEffects();
			if (paramStatusEffects == null || paramStatusEffects.Length == 0)
			{
				yield break;
			}
			foreach (CharacterState target in cardEffectParams.targets)
			{
				if ((Object)(object)target == (Object)null || target.IsDestroyed || !target.GetIsClone())
				{
					continue;
				}
				StatusEffectStackData[] array = paramStatusEffects;
				foreach (StatusEffectStackData val in array)
				{
					if (val != null && val.count > 0 && target.GetStatusEffectStacks(val.statusId) <= 0)
					{
						AddStatusEffectParams val2 = new AddStatusEffectParams
						{
							sourceRelicState = cardEffectParams.sourceRelic,
							sourceIsHero = ((int)cardEffectState.GetSourceTeamType() == 1),
							fromEffectType = ((object)this).GetType()
						};
						target.AddStatusEffect(val.statusId, val.count, val2, (CharacterState)null, false, cardEffectParams.isFromHiddenTrigger, true, false, false);
					}
				}
			}
		}

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0025: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			PropDescriptions val = new PropDescriptions { };
			string fieldName;
			((Dictionary<string, PropDescription>)val)[fieldName] = new PropDescription("Status Effects", "Estados que se aplican, y solo, a las unidades marcadas como clon.", (Type)null, false);
			return val;
		}
	}
	public sealed class CardEffectCopyWithStatuses : CardEffectBase
	{
		private int numCopiesOfEachUnit;

		private bool shouldCopyHeroStats;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0024: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0043: Expected O, but got Unknown
			//IL_0044: Expected O, but got Unknown
			PropDescriptions val = new PropDescriptions { };
			string fieldName;
			((Dictionary<string, PropDescription>)val)[fieldName] = new PropDescription("Num Copies Of Each Unit", "", (Type)null, false);
			string fieldName2 = CardEffectFieldNamesHelper.GetFieldName((CardEffectFieldNames)7);
			((Dictionary<string, PropDescription>)val)[fieldName2] = new PropDescription("Copy Hero Stats", "Only applies when copying hero units - copies status effects after spawning a new unit.", (Type)null, false);
			return val;
		}

		public override void Setup(CardEffectState cardEffectState)
		{
			((CardEffectBase)this).Setup(cardEffectState);
			numCopiesOfEachUnit = cardEffectState.GetParamInt();
			shouldCopyHeroStats = cardEffectState.GetParamBool();
		}

		public override bool TestEffect(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers)
		{
			return cardEffectParams.targets.Count > 0;
		}

		public override IEnumerator ApplyEffect(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			int numSpawns = 0;
			MonsterManager monsterManager = coreGameManagers.GetMonsterManager();
			HeroManager heroManager = coreGameManagers.GetHeroManager();
			RoomManager roomManager = coreGameManagers.GetRoomManager();
			SaveManager saveManager = coreGameManagers.GetSaveManager();
			CombatManager combatManager = coreGameManagers.GetCombatManager();
			List<CharacterState> originalUnitsInRoom = default(List<CharacterState>);
			UsingGenericPoolObject<List<CharacterState>> list = GenericPools.GetList<CharacterState>(ref originalUnitsInRoom);
			try
			{
				RoomState room = roomManager.GetRoom(cardEffectParams.selectedRoom);
				if ((Object)(object)room != (Object)null)
				{
					room.AddCharactersToList(originalUnitsInRoom, (Type)3, false, true);
				}
				foreach (CharacterState copyUnit in cardEffectParams.targets)
				{
					if ((Object)(object)copyUnit == (Object)null || copyUnit.IsDestroyed || !copyUnit.IsAlive)
					{
						continue;
					}
					SpawnPoint spawnPoint = copyUnit.GetSpawnPoint(false);
					if (spawnPoint == null)
					{
						continue;
					}
					for (int i = 0; i < numCopiesOfEachUnit; i++)
					{
						if ((int)cardEffectState.GetTargetTeamType() == 1)
						{
							CharacterState newHero = null;
							CharacterState val = (shouldCopyHeroStats ? copyUnit : null);
							yield return heroManager.SpawnHeroInRoom(copyUnit.GetSourceCharacterData(), cardEffectParams.selectedRoom, newHero, saveManager.PreviewMode, val);
							if ((Object)(object)newHero != (Object)null)
							{
								int num = numSpawns;
								numSpawns = num + 1;
							}
							continue;
						}
						CharacterState createdClone = null;
						yield return monsterManager.CloneMonsterState(copyUnit, cardEffectParams.selectedRoom, (Action<CharacterState>)delegate(CharacterState newCharacter)
						{
							if ((Object)(object)newCharacter != (Object)null)
							{
								int num2 = numSpawns;
								numSpawns = num2 + 1;
								createdClone = newCharacter;
							}
						}, coreGameManagers, (SpawnMode)3, spawnPoint, (Action<CharacterState>)null, false, (CharacterData)null, (List<string>)null, (AddStatusEffectParams)null, true, (Action<CharacterState>)null, (CardState)null);
						if (!((Object)(object)createdClone != (Object)null) || createdClone.IsDestroyed)
						{
							continue;
						}
						StatusEffectStackData[] paramStatusEffects = cardEffectState.GetSourceCardEffectData().GetParamStatusEffects();
						foreach (StatusEffectStackData val2 in paramStatusEffects)
						{
							if (!createdClone.HasStatusEffect(val2.statusId))
							{
								createdClone.AddStatusEffect(val2.statusId, val2.count, (CharacterState)null, false, false);
							}
						}
					}
				}
				if (numSpawns > 0)
				{
					foreach (CharacterState item in originalUnitsInRoom)
					{
						if (!((Object)(object)item == (Object)null) && !item.IsDestroyed && item.IsAlive)
						{
							combatManager.QueueTrigger(item, (Trigger)20, (CharacterState)null, true, true, (FireTriggersData)null, numSpawns, (CharacterTriggerState)null);
						}
					}
				}
				if (numSpawns > 1 && !saveManager.PreviewMode)
				{
					if ((int)cardEffectState.GetTargetTeamType() == 1)
					{
						yield return roomManager.HandleRoomUnitOrderPossiblyChanged();
					}
					else
					{
						yield return roomManager.GetRoomUI().CenterCharacters(cardEffectParams.GetSelectedRoom(coreGameManagers.GetRoomManager()), false, false, false);
					}
				}
				monsterManager.RefreshCharacterAbilityUI();
				monsterManager.RefreshEquipmentUI();
			}
			finally
			{
				((IDisposable)list/*cast due to .constrained prefix*/).Dispose();
			}
		}
	}
	public sealed class CardEffectMultiplyNegativeStatusEffects : CardEffectBase
	{
		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return ((CardEffectBase)new CardEffectMultiplyAllStatusEffects()).CreateEditorInspectorDescriptions();
		}

		public override IEnumerator ApplyEffect(CardEffectState effect, CardEffectParams args, ICoreGameManagers managers, ISystemManagers systems)
		{
			AddStatusEffectParams val = new AddStatusEffectParams();
			val.ApplyEffectParams<CardEffectMultiplyNegativeStatusEffects>(effect, args);
			List<StatusEffectStack> list = new List<StatusEffectStack>();
			for (int num = args.targets.Count - 1; num >= 0; num--)
			{
				CharacterState val2 = args.targets[num];
				if (!((Object)(object)val2 == (Object)null) && !val2.IsDestroyed)
				{
					list.Clear();
					val2.GetStatusEffects(ref list, false);
					foreach (StatusEffectStack item in list)
					{
						if ((int)item.State.GetDisplayCategory() == 1)
						{
							int num2 = item.Count * (effect.GetParamInt() - 1);
							if (num2 > 0)
							{
								val2.AddStatusEffect(item.State.GetStatusId(), num2, val, (CharacterState)null, true, args.isFromHiddenTrigger, true, false, false);
							}
						}
					}
				}
			}
			yield break;
		}
	}
	internal class StatusEffectFranticState : StatusEffectState
	{
		public override bool TestTrigger(InputTriggerParams input, OutputTriggerParams output, ICoreGameManagers core)
		{
			CharacterState associatedCharacter = input.associatedCharacter;
			if ((Object)(object)associatedCharacter != (Object)null && !associatedCharacter.IsDestroyed && associatedCharacter.IsAlive && output.canAttackOrHeal && !FranticBossImmunity.IsBoss(associatedCharacter))
			{
				return associatedCharacter.GetStatusEffectStacks(((StatusEffectState)this).GetStatusId()) > 0;
			}
			return false;
		}

		protected override IEnumerator OnTriggered(InputTriggerParams input, OutputTriggerParams output, ICoreGameManagers core)
		{
			CharacterState associatedCharacter = input.associatedCharacter;
			if (!((Object)(object)associatedCharacter == (Object)null) && !associatedCharacter.IsDestroyed && associatedCharacter.IsAlive && !FranticNativeTurn.Activate(associatedCharacter, ((StatusEffectState)this).GetStatusId()))
			{
				output.canAttackOrHeal = false;
			}
			yield break;
		}

		public override int GetEffectMagnitude(int stacks = 1)
		{
			CharacterState associatedCharacter = ((StatusEffectState)this).GetAssociatedCharacter();
			if (!((Object)(object)associatedCharacter == (Object)null) && !associatedCharacter.IsDestroyed)
			{
				return associatedCharacter.GetAttackDamage();
			}
			return 0;
		}
	}
	internal static class FranticNativeTurn
	{
		internal sealed class Scope
		{
			internal CharacterState Unit;

			internal bool Activated;

			internal bool Consumed;

			internal string StatusId;
		}

		private static readonly List<Scope> Scopes = new List<Scope>();

		internal static bool Activate(CharacterState unit, string statusId)
		{
			for (int num = Scopes.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)Scopes[num].Unit == (Object)(object)unit)
				{
					Scopes[num].Activated = true;
					Scopes[num].StatusId = statusId;
					return true;
				}
			}
			return false;
		}

		internal static void ConsumeForAttack(CharacterState unit)
		{
			if ((Object)(object)unit == (Object)null || unit.IsDestroyed || !unit.IsAlive)
			{
				return;
			}
			for (int num = Scopes.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)Scopes[num].Unit == (Object)(object)unit)
				{
					Scope scope = Scopes[num];
					if (scope.Activated && !scope.Consumed)
					{
						scope.Consumed = true;
						unit.RemoveStatusEffect(scope.StatusId, 1, false);
					}
					break;
				}
			}
		}

		internal static bool IsActive(CharacterState unit)
		{
			for (int num = Scopes.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)Scopes[num].Unit == (Object)(object)unit)
				{
					return Scopes[num].Activated;
				}
			}
			return false;
		}

		internal static IEnumerator Run(IEnumerator original, CharacterState unit)
		{
			if (!((Object)(object)unit == (Object)null) && !unit.IsDestroyed)
			{
				Scope scope = new Scope
				{
					Unit = unit
				};
				Scopes.Add(scope);
				try
				{
					yield return original;
				}
				finally
				{
					Scopes.Remove(scope);
				}
			}
		}
	}
	[HarmonyPatch(typeof(CombatManager), "RunUnitTurn")]
	internal static class FranticNativeTurnPatch
	{
		[HarmonyPrefix]
		private static void Before(CharacterState attackerState, ref Action<int> perAttackVfxCallback)
		{
			Action<int> original = perAttackVfxCallback;
			perAttackVfxCallback = delegate(int attackIndex)
			{
				FranticNativeTurn.ConsumeForAttack(attackerState);
				original?.Invoke(attackIndex);
			};
		}

		[HarmonyPostfix]
		private static void After(CharacterState attackerState, ref IEnumerator __result)
		{
			__result = FranticNativeTurn.Run(__result, attackerState);
		}
	}
	[HarmonyPatch(typeof(CombatManager), "CollectTargetDataInRunAttack")]
	internal static class FranticNativeTargetsPatch
	{
		[HarmonyPrefix]
		private static void Before(CharacterState attackerState, ref ICharacterManager targetsManager, ref List<CharacterState> overrideTargets)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)attackerState == (Object)null || attackerState.IsDestroyed || !FranticNativeTurn.IsActive(attackerState))
			{
				return;
			}
			targetsManager = attackerState.GetCharacterManager();
			List<CharacterState> list = new List<CharacterState>();
			SpawnPoint spawnPoint = attackerState.GetSpawnPoint(false);
			if (spawnPoint != null)
			{
				RoomState roomOwner = spawnPoint.GetRoomOwner();
				if (roomOwner != null)
				{
					roomOwner.AddCharactersToList(list, attackerState.GetTeamType(), false, true);
				}
			}
			CharacterState val = ((IEnumerable<CharacterState>)list).FirstOrDefault((Func<CharacterState, bool>)((CharacterState unit) => (Object)(object)unit != (Object)null && !unit.IsDestroyed && unit.IsAlive));
			overrideTargets = new List<CharacterState>();
			if ((Object)(object)val != (Object)null)
			{
				overrideTargets.Add(val);
			}
			else if (attackerState.IsAlive)
			{
				overrideTargets.Add(attackerState);
			}
		}

		[HarmonyPostfix]
		private static void After(CharacterState attackerState, ref TargetMode attackTargetMode, ref CollectTargetsData __result)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)attackerState == (Object)null) && !attackerState.IsDestroyed && FranticNativeTurn.IsActive(attackerState))
			{
				attackTargetMode = (TargetMode)2;
				__result.targetMode = attackTargetMode;
			}
		}
	}
	internal class StatusEffectMarkerState : StatusEffectState
	{
	}
	public sealed class RoomStateSuccClanTurnStartEffects : RoomStateModifierBase
	{
		private readonly List<CardEffectState> effects = new List<CardEffectState>();

		private int lastAppliedTurn = -1;

		public override void Initialize(RoomModifierData data, SaveManager save)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			((RoomStateModifierBase)this).Initialize(data, save);
			effects.Clear();
			lastAppliedTurn = -1;
			foreach (CardEffectData paramCardEffectDatum in data.GetParamCardEffectData())
			{
				CardEffectState val = new CardEffectState();
				val.Setup(paramCardEffectDatum, (CardState)null, (SaveManager)null);
				effects.Add(val);
			}
		}

		public IEnumerator Apply(RoomState room, ICoreGameManagers core)
		{
			int turnCount = core.GetCombatManager().GetTurnCount();
			if (lastAppliedTurn != turnCount)
			{
				lastAppliedTurn = turnCount;
				yield return ((RoomStateModifierBase)this).ShowTriggeredVFX(room, core);
				yield return core.GetCombatManager().ApplyEffects(effects, room.GetRoomIndex(), (CardState)null, false, (RelicState)null, (CharacterState)null, (SpawnPoint)null, true, (ApplyPreEffectsVfxAction)delegate(CardEffectState state, CardEffectParams parameters)
				{
					SuccClanPresentation.PlayEffect(state, parameters, core);
				}, (ApplyPreEffectsAction)null, (ApplyEffectsAction)null, false, (CharacterState)null, (CharacterState)null, 1, (CharacterState)null, false, (CardTriggerType)2, (CharacterTriggerState)null, (CharacterState)null, (RoomState)null, false, false, (CharacterState)null);
			}
		}
	}
	[HarmonyPatch(typeof(CardManager), "DrawHand")]
	internal static class SuccClanTurnStartRoomPatch
	{
		private static void Postfix(AllGameManagers ___allGameManagers, ref IEnumerator __result)
		{
			__result = AfterDraw(__result, ___allGameManagers);
		}

		private static IEnumerator AfterDraw(IEnumerator original, AllGameManagers managers)
		{
			yield return original;
			if ((Object)(object)managers == (Object)null)
			{
				yield break;
			}
			ICoreGameManagers core = managers.GetCoreManagers();
			if ((int)core.GetCombatManager().GetCombatPhase() != 3)
			{
				yield break;
			}
			RoomManager rooms = core.GetRoomManager();
			for (int i = 0; i < rooms.GetNumRooms(); i++)
			{
				RoomState room = rooms.GetRoom(i);
				if ((Object)(object)room == (Object)null)
				{
					continue;
				}
				foreach (RoomStateSuccClanTurnStartEffects item in room.GetRoomStateModifiersFromTrainRoomAttachments<RoomStateSuccClanTurnStartEffects>((Type)2).ToList())
				{
					yield return item.Apply(room, core);
				}
			}
		}
	}
	[BepInPlugin("mt2_succclan.Plugin", "mt2_succclan.Plugin", "0.2.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger = new ManualLogSource("mt2_succclan.Plugin");

		internal static ClassData? ClanInstance;

		public void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("mt2_succclan.Plugin").PatchAll();
			Railhead.GetBuilder().Configure("mt2_succclan.Plugin", (Action<IConfigurationBuilder>)delegate(IConfigurationBuilder c)
			{
				string[] jsonPaths = new string[62]
				{
					"json/plugin.json", "json/audiovisual.json", "json/class.json", "json/essences.json", "json/status_effects/psionic.json", "json/status_effects/frantic.json", "json/champions/champion_KnightMare.json", "json/champions/champion_ShadowLady.json", "json/spells/card_BloodCarnival.json", "json/spells/card_CubusSpike.json",
					"json/spells/card_DangerousGame.json", "json/spells/card_DarkFury.json", "json/spells/card_DarkPact.json", "json/spells/card_DepressionWhisper.json", "json/spells/card_DreadShot.json", "json/spells/card_Flogging.json", "json/spells/card_ForTheQueen.json", "json/spells/card_IllusionTwins.json", "json/spells/card_Inception.json", "json/spells/card_InsanityReach.json",
					"json/spells/card_MindBurning.json", "json/spells/card_MindDomination.json", "json/spells/card_ObsessingShard.json", "json/spells/card_PainAndPleasure.json", "json/spells/card_ParadoxTome.json", "json/spells/card_PiercingShriek.json", "json/spells/card_PlagueBoost.json", "json/spells/card_PowerSiphon.json", "json/spells/card_ProfaneAscending.json", "json/spells/card_ShadowEmbrace.json",
					"json/spells/card_VitalityExtraction.json", "json/rooms/room_SpectralRefuge.json", "json/rooms/room_ObsessionVault.json", "json/equipment/equip_WhisperingBlade.json", "json/equipment/equip_MourningVeil.json", "json/relics/relic_AbyssCrown.json", "json/relics/relic_DemonBlood.json", "json/relics/relic_DesireCrystal.json", "json/relics/relic_FlareRibbon.json", "json/relics/relic_FleshRing.json",
					"json/relics/relic_MutantElixirs.json", "json/relics/relic_NetherBlossom.json", "json/relics/relic_ObsessingAromatherapy.json", "json/relics/relic_PoisonSerum.json", "json/relics/relic_ProfaneCrossbow.json", "json/relics/relic_ShadowCloak.json", "json/units/unit_AbyssPrincess.json", "json/units/unit_ArroganceGhost.json", "json/units/unit_ChaosCreation.json", "json/units/unit_DemonPioneer.json",
					"json/units/unit_EndlessShadow.json", "json/units/unit_EnvyGhost.json", "json/units/unit_GluttonyGhost.json", "json/units/unit_GreedGhost.json", "json/units/unit_IncubusButcher.json", "json/units/unit_LustGhost.json", "json/units/unit_Oolioddroo.json", "json/units/unit_ShadowWarrior.json", "json/units/unit_SlothGhost.json", "json/units/unit_SuccbusTorturer.json",
					"json/units/unit_Vrolikai.json", "json/units/unit_WrathGhost.json"
				};
				string directoryName = Path.GetDirectoryName(typeof(Plugin).Assembly.Location);
				string[] array = jsonPaths;
				foreach (string path in array)
				{
					string text = Path.Combine(directoryName, path);
					if (!File.Exists(text))
					{
						Logger.LogError((object)("SuccClan content file missing: " + text + ". Reinstall the complete mod package; keep json/ and textures/ beside the DLL."));
						throw new FileNotFoundException("SuccClan content is incomplete or incorrectly installed.", text);
					}
				}
				ConfigurationExtensions.AddMergedJsonFile(c, (Action<MergedJsonConfigurationSource>)delegate(MergedJsonConfigurationSource source)
				{
					source.Paths = new List<string>(jsonPaths);
					source.Optional = false;
				});
				Roundhouse.WhenReady("mt2_succclan.Plugin", (Action<GameDataManager>)delegate(GameDataManager ctx)
				{
					string[] array2 = new string[12]
					{
						"KnightMareCardArt", "ShadowLadyCardArt", "CubusSpikeArt", "DepressionWhisperArt", "IllusionTwinsArt", "InsanityReachArt", "ParadoxTomeArt", "PlagueBoostArt", "AbyssPrincessCardArt", "ArroganceGhostCardArt",
						"EndlessShadowCardArt", "ShadowWarriorCardArt"
					};
					foreach (string text2 in array2)
					{
						SuccSetupChampionCardAnimations.SetupCardArt(ctx.GetCardArt(text2, (string)null));
					}
					ClanInstance = ctx.GetClan("ClassSuccubus", (string)null);
				});
				Logger.LogInfo((object)$"SuccClan configured {jsonPaths.Length} JSON files from {directoryName}.");
			});
			Logger.LogInfo((object)"Plugin mt2_succclan.Plugin is loaded!");
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "mt2_succclan.Plugin";

		public const string PLUGIN_NAME = "mt2_succclan.Plugin";

		public const string PLUGIN_VERSION = "0.2.1";
	}
	public sealed class CardTraitBlightHandDamage : CardTraitState
	{
		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}

		public override bool HasMultiWordDesc()
		{
			return true;
		}

		public override string GetCurrentEffectText(CardStatistics? stats, SaveManager? save, RelicManager? relics)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			CardState card = ((CardTraitState)this).GetCard();
			if (card == null)
			{
				return string.Empty;
			}
			List<CardEffectState> effectStates = card.GetEffectStates();
			if (effectStates.Count == 0)
			{
				return string.Empty;
			}
			int paramInt = effectStates[0].GetParamInt();
			if ((Object)(object)stats == (Object)null || !stats.GetIsInActiveBattle() || (Object)(object)AllGameManagers.Instance == (Object)null)
			{
				if (paramInt <= 0)
				{
					return string.Empty;
				}
				return string.Format(LocalizationExtensions.Localize("CardTraitScalingAddDamage_ExtraDamage_XCostOutsideBattle_CardText", (ILocalizationParameterContext)null), paramInt, "tempUpgradeHighlight");
			}
			CardManager cardManager = AllGameManagers.Instance.GetCardManager();
			if ((Object)(object)cardManager == (Object)null)
			{
				return string.Empty;
			}
			int num = IEnumerableUtility.Count<CardState>(cardManager.GetHand(false), (Func<CardState, bool>)((CardState candidate) => candidate != card && (int)candidate.GetCardType() == 5));
			return LocalizationExtensions.Localize("CardTraitScalingAddDamage_CurrentScaling_CardText", (ILocalizationParameterContext)new LocalizedIntegers(new int[1] { paramInt + num * ((CardTraitState)this).GetParamInt() }));
		}

		public override int OnApplyingDamage(ApplyingDamageParameters damage, ICoreGameManagers core)
		{
			//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)
			int num = IEnumerableUtility.Count<CardState>(core.GetCardManager().GetHand(false), (Func<CardState, bool>)((CardState card) => card != damage.damageSourceCard && (int)card.GetCardType() == 5));
			return damage.damage + num * ((CardTraitState)this).GetParamInt();
		}
	}
	public sealed class CardEffectDiscardAllBlights : CardEffectBase, ICardEffectDiscards, ICardEffect
	{
		public override bool CanPlayAfterBossDead => false;

		public override bool CanApplyInPreviewMode => false;

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}

		public override IEnumerator ApplyEffect(CardEffectState state, CardEffectParams parameters, ICoreGameManagers core, ISystemManagers systems)
		{
			CardManager manager = core.GetCardManager();
			List<CardState> list = (from card in manager.GetHand(true)
				where card != parameters.playedCard && (int)card.GetCardType() == 5
				select card).ToList();
			foreach (CardState item in list)
			{
				yield return manager.DiscardCard(new DiscardCardParams
				{
					discardCard = item,
					triggeredByCard = true,
					triggeredCard = parameters.playedCard,
					wasPlayed = false
				}, false);
			}
		}
	}
	internal static class FranticBossImmunity
	{
		internal const string StatusId = "mt2_succclan.Plugin_frantic";

		internal static bool IsBoss(CharacterState character)
		{
			if ((Object)(object)character != (Object)null && !character.IsDestroyed)
			{
				if (!character.IsAnyBoss())
				{
					return character.IsCompanionBoss();
				}
				return true;
			}
			return false;
		}

		internal static bool Blocks(CharacterState character, string statusId)
		{
			if (string.Equals(statusId, "mt2_succclan.Plugin_frantic", StringComparison.OrdinalIgnoreCase))
			{
				if (!((Object)(object)character == (Object)null) && !character.IsDestroyed)
				{
					return IsBoss(character);
				}
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(CharacterState), "IsImmune")]
	internal static class FranticBossImmunityQueryPatch
	{
		private static void Postfix(CharacterState __instance, string statusEffectId, ref bool __result)
		{
			if (FranticBossImmunity.Blocks(__instance, statusEffectId))
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(CharacterState), "AddStatusEffect", new Type[]
	{
		typeof(string),
		typeof(int),
		typeof(AddStatusEffectParams),
		typeof(CharacterState),
		typeof(bool),
		typeof(bool),
		typeof(bool),
		typeof(bool),
		typeof(bool)
	})]
	internal static class FranticBossApplicationPatch
	{
		private static bool Prefix(CharacterState __instance, string statusId)
		{
			return !FranticBossImmunity.Blocks(__instance, statusId);
		}
	}
	public sealed class CardEffectKnightmareRebirth : CardEffectBase
	{
		internal const string Psionic = "mt2_succclan.Plugin_psionic";

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}

		internal static int GetRebirthCost(CardEffectState effect, CharacterState source)
		{
			return effect.GetUnmodifiedParamInt() + source.GetAppliedUpgradeCount(effect.GetParamCardUpgradeData());
		}

		internal static CardEffectState? FindEffect(CharacterState source)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null || source.IsDestroyed || source.HasStatusEffect("silenced") || source.HasStatusEffect("muted"))
			{
				return null;
			}
			foreach (CharacterTriggerState trigger in source.GetTriggers())
			{
				if ((int)trigger.GetTrigger() != 0)
				{
					continue;
				}
				foreach (CardEffectState effectState in trigger.GetEffectStates())
				{
					if (effectState.GetCardEffect() is CardEffectKnightmareRebirth)
					{
						return effectState;
					}
				}
			}
			return null;
		}

		internal static bool CanRebirth(CharacterState source, CardEffectState? effect)
		{
			if ((Object)(object)source != (Object)null && !source.IsDestroyed && source.IsDead && source.GetMaxHP() > 0 && effect != null && (Object)(object)effect.GetParamCardUpgradeData() != (Object)null)
			{
				SpawnPoint spawnPoint = source.GetSpawnPoint(false);
				if (spawnPoint != null)
				{
					RoomState roomOwner = spawnPoint.GetRoomOwner();
					if (((roomOwner != null) ? new bool?(roomOwner.IsRoomEnabled()) : ((bool?)null)) == true)
					{
						return source.GetStatusEffectStacks("mt2_succclan.Plugin_psionic") >= GetRebirthCost(effect, source);
					}
				}
			}
			return false;
		}

		public override bool TestEffect(CardEffectState effect, CardEffectParams p, ICoreGameManagers core)
		{
			return false;
		}

		public override IEnumerator ApplyEffect(CardEffectState effect, CardEffectParams p, ICoreGameManagers core, ISystemManagers systems)
		{
			yield break;
		}
	}
	internal static class KnightmareNativeRebirth
	{
		private static readonly Dictionary<CharacterState, CardEffectState> Pending = new Dictionary<CharacterState, CardEffectState>();

		internal static IEnumerator Check(IEnumerator original, CharacterState source, bool ignoreTriggers)
		{
			if ((Object)(object)source == (Object)null || source.IsDestroyed)
			{
				yield break;
			}
			CardEffectState val = ((ignoreTriggers || source.GetStatusEffectStacks("undying") > 0) ? null : CardEffectKnightmareRebirth.FindEffect(source));
			bool prepared = !Pending.ContainsKey(source) && CardEffectKnightmareRebirth.CanRebirth(source, val);
			if (prepared)
			{
				source.AddStatusEffect("undying", 1, new AddStatusEffectParams(), (CharacterState)null, false, false, false, false, true);
				prepared = source.GetStatusEffectStacks("undying") > 0;
				if (prepared)
				{
					source.RemoveStatusEffect("mt2_succclan.Plugin_psionic", CardEffectKnightmareRebirth.GetRebirthCost(val, source), false);
					Pending.Add(source, val);
				}
			}
			try
			{
				yield return original;
			}
			finally
			{
				if (prepared)
				{
					Pending.Remove(source);
				}
			}
		}

		internal static IEnumerator Revive(IEnumerator original, CharacterState source)
		{
			bool first = true;
			try
			{
				while (original.MoveNext())
				{
					if (first && (Object)(object)source != (Object)null && !source.IsDestroyed && Pending.TryGetValue(source, out CardEffectState value))
					{
						first = false;
						Pending.Remove(source);
						CardUpgradeState upgrade = new CardUpgradeState();
						upgrade.Setup(value.GetParamCardUpgradeData(), false, false);
						yield return source.ApplyCardUpgrade(upgrade, false, upgrade.GetCardUpgradeDataId(), true, false, (CardState)null, (Action<UpgradeApplicationResult>)null, (TrainRoomAttachmentState)null, false);
						if (!source.IsDestroyed)
						{
							if (!source.PreviewMode)
							{
								CardState spawnerCard = source.GetSpawnerCard();
								if (spawnerCard != null)
								{
									spawnerCard.GetTemporaryCardStateModifiers().AddUpgrade(upgrade, (CardStateModifiers)null);
									spawnerCard.UpdateCardBodyText((SaveManager)null);
								}
							}
							source.SetHealth(source.GetMaxHP(), source.GetMaxHP());
						}
					}
					yield return original.Current;
				}
			}
			finally
			{
				(original as IDisposable)?.Dispose();
			}
		}
	}
	[HarmonyPatch(typeof(CharacterState), "CheckDeathCardTriggers")]
	internal static class KnightmareDeathPatch
	{
		[HarmonyPostfix]
		private static void After(CharacterState __instance, bool ignoreTriggers, ref IEnumerator __result)
		{
			__result = KnightmareNativeRebirth.Check(__result, __instance, ignoreTriggers);
		}
	}
	[HarmonyPatch(typeof(CharacterState), "ReviveFromUndyingStatus")]
	internal static class KnightmareRevivePatch
	{
		[HarmonyPostfix]
		private static void After(CharacterState __instance, ref IEnumerator __result)
		{
			__result = KnightmareNativeRebirth.Revive(__result, __instance);
		}
	}
	public sealed class CardEffectKnightmareHarvest : CardEffectAddStatusEffect
	{
		public override bool TestEffect(CardEffectState effect, CardEffectParams p, ICoreGameManagers core)
		{
			if ((Object)(object)p.selfTarget != (Object)null && !p.selfTarget.IsDestroyed && (Object)(object)p.dyingCharacter != (Object)(object)p.selfTarget)
			{
				return ((CardEffectAddStatusEffect)this).TestEffect(effect, p, core);
			}
			return false;
		}

		public override IEnumerator ApplyEffect(CardEffectState effect, CardEffectParams p, ICoreGameManagers core, ISystemManagers systems)
		{
			if (((CardEffectBase)this).TestEffect(effect, p, core))
			{
				yield return <>n__0(effect, p, core, systems);
			}
		}

		[CompilerGenerated]
		[DebuggerHidden]
		private IEnumerator <>n__0(CardEffectState cardEffectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers, ISystemManagers sysManagers)
		{
			return ((CardEffectAddStatusEffect)this).ApplyEffect(cardEffectState, cardEffectParams, coreGameManagers, sysManagers);
		}
	}
	[HarmonyPatch(typeof(CardTextReplacements), "GetCardTextReplacementIntegerValue")]
	internal static class KnightmareRebirthCostText
	{
		[HarmonyPostfix]
		private static void After(ILocalizationEffectPower localizationEffectPower, CharacterState characterContext, TranslationToken token, ref int? __result)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			if ((Object)(object)characterContext == (Object)null || characterContext.IsDestroyed)
			{
				return;
			}
			CharacterTriggerState val = (CharacterTriggerState)(object)((localizationEffectPower is CharacterTriggerState) ? localizationEffectPower : null);
			if (val == null)
			{
				return;
			}
			TranslationTokenCardText val2 = (TranslationTokenCardText)(object)((token is TranslationTokenCardText) ? token : null);
			if (val2 == null || val2.elements.Count != 1)
			{
				return;
			}
			TranslationTokenCardTextElement val3 = val2.elements[0];
			if ((int)val3.ElementType == 0 && val3.Index == 0 && (int)val3.SubType == 1)
			{
				CardEffectState val4 = val.GetEffectStates().FirstOrDefault();
				if (((val4 != null) ? val4.GetCardEffect() : null) is CardEffectKnightmareRebirth)
				{
					__result = CardEffectKnightmareRebirth.GetRebirthCost(val4, characterContext);
				}
			}
		}
	}
	internal static class SuccClanPresentation
	{
		private static readonly HashSet<string> ReportedErrors = new HashSet<string>(StringComparer.Ordinal);

		internal static bool CanPresent(ICoreGameManagers core)
		{
			if (core != null && !core.GetSaveManager().PreviewMode && (Object)(object)AllGameManagers.Instance != (Object)null)
			{
				return !AllGameManagers.Instance.GetScreenManager().GetScreenActive((ScreenName)25);
			}
			return false;
		}

		private static bool IsClanCard(CardState? card)
		{
			return SuccClanEffectContext.IsCard(card);
		}

		private static bool IsClanCharacter(CharacterState? character)
		{
			return SuccClanEffectContext.IsCharacter(character);
		}

		internal static bool IsClanContext(CardEffectState state, CardEffectParams parameters)
		{
			if (!IsClanCard(parameters.playedCard) && !IsClanCard(state.GetParentCardState()) && !IsClanCharacter(parameters.selfTarget))
			{
				return IsClanCharacter(parameters.characterThatActivatedAbility);
			}
			return true;
		}

		internal static void PlayEffect(CardEffectState state, CardEffectParams parameters, ICoreGameManagers core)
		{
			if (!CanPresent(core))
			{
				return;
			}
			AllGameManagers instance = AllGameManagers.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			try
			{
				RoomState room = core.GetRoomManager().GetRoom(parameters.selectedRoom);
				state.PlayEffectVfx(parameters, core, room, instance.GetGameVfxManager(), false);
			}
			catch (Exception ex)
			{
				if (ReportedErrors.Add(ex.GetType().FullName ?? ex.GetType().Name))
				{
					Plugin.Logger.LogWarning((object)("SuccClan presentation failed; gameplay continues: " + ex.Message));
				}
			}
		}

		internal static void PlayEffectSound(CardEffectState state, CardEffectParams parameters, ICoreGameManagers core)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			if (CanPresent(core) && IsClanContext(state, parameters))
			{
				ICardEffect cardEffect = state.GetCardEffect();
				if ((cardEffect is CardEffectDamage || cardEffect is CardEffectDamagePerSourceAttack) && parameters.targets.Count > 0 && (Object)(object)parameters.selfTarget == (Object)null && (int)state.GetTargetMode() != 21)
				{
					SoundManager.PlaySfxSignal.Dispatch("Combat_Attack");
				}
				else if (cardEffect is CardEffectBump && parameters.targets.Count > 0)
				{
					SoundManager.PlaySfxSignal.Dispatch("Combat_Ascend");
				}
			}
		}

		internal static void ShowSpawn(CharacterState character)
		{
			AllGameManagers instance = AllGameManagers.Instance;
			if ((Object)(object)instance == (Object)null || !IsClanCharacter(character) || character.PreviewMode || character.SpawnedInPreviewMode || !character.IsAlive || instance.GetScreenManager().GetScreenActive((ScreenName)25))
			{
				return;
			}
			try
			{
				VfxAtLoc deathVfx = character.GetSourceCharacterData().GetDeathVfx();
				CharacterUI characterUI = character.GetCharacterUI();
				if (deathVfx != null && (Object)(object)characterUI != (Object)null)
				{
					characterUI.ShowEffectVFX(character, deathVfx, 0, (EffectVfxReason)0);
				}
			}
			catch (Exception ex)
			{
				if (ReportedErrors.Add("Spawn:" + ex.GetType().FullName))
				{
					Plugin.Logger.LogWarning((object)("SuccClan spawn visual failed; gameplay continues: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameEffectHelper), "ApplyEffect")]
	internal static class SuccClanEffectPresentationPatch
	{
		[HarmonyPrefix]
		private static void BeforeApply(ref ApplyPreEffectsVfxAction onPreEffectsFiredVfx, ICoreGameManagers coreGameManagers)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (!SuccClanPresentation.CanPresent(coreGameManagers))
			{
				return;
			}
			ApplyPreEffectsVfxAction original = onPreEffectsFiredVfx;
			onPreEffectsFiredVfx = (ApplyPreEffectsVfxAction)delegate(CardEffectState state, CardEffectParams parameters)
			{
				ApplyPreEffectsVfxAction obj = original;
				if (obj != null)
				{
					obj.Invoke(state, parameters);
				}
				if (SuccClanPresentation.IsClanContext(state, parameters))
				{
					if (original == null)
					{
						SuccClanPresentation.PlayEffect(state, parameters, coreGameManagers);
					}
					SuccClanPresentation.PlayEffectSound(state, parameters, coreGameManagers);
				}
			};
		}
	}
	[HarmonyPatch(typeof(CharacterState), "Setup")]
	internal static class SuccClanSpawnPresentationPatch
	{
		[HarmonyPostfix]
		private static IEnumerator AfterSetup(IEnumerator __result, CharacterState __instance)
		{
			yield return __result;
			SuccClanPresentation.ShowSpawn(__instance);
		}
	}
	internal static class SuccSetupChampionCardAnimations
	{
		internal static void SetupCardArt(GameObject root)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null || !TryProfile(((Object)root).name, out var hue, out var focus, out var secondFocus, out var period, out var pulseSpeed))
			{
				return;
			}
			Transform obj = root.transform.Find("CardSprite");
			Image val = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)root.GetComponent<SuccChampionCardAnimation>() != (Object)null))
			{
				if ((Object)(object)root.GetComponent<RectMask2D>() == (Object)null)
				{
					root.AddComponent<RectMask2D>();
				}
				GameObject val2 = new GameObject("SuccChampionCardAtmosphere", new Type[2]
				{
					typeof(RectTransform),
					typeof(CanvasRenderer)
				})
				{
					layer = root.layer
				};
				val2.transform.SetParent(root.transform, false);
				RectTransform component = val2.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				SuccChampionCardAtmosphere succChampionCardAtmosphere = val2.AddComponent<SuccChampionCardAtmosphere>();
				((Graphic)succChampionCardAtmosphere).raycastTarget = false;
				succChampionCardAtmosphere.Configure(hue, focus, secondFocus, pulseSpeed);
				root.AddComponent<SuccChampionCardAnimation>().Configure(val, succChampionCardAtmosphere, period);
			}
		}

		private static bool TryProfile(string fullId, out Color hue, out Vector2 focus, out Vector2 secondFocus, out float period, out float pulseSpeed)
		{
			//IL_0010: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			hue = new Color(0.65f, 0.2f, 1f);
			focus = new Vector2(0.5f, 0.5f);
			secondFocus = new Vector2(-1f, -1f);
			period = 7f;
			pulseSpeed = 1.4f;
			switch (StringExtensions.ExtractId(fullId, "mt2_succclan.Plugin", "GameObject", "CardArt"))
			{
			case "KnightMareCardArt":
				hue = new Color(0.12f, 0.72f, 1f);
				focus = new Vector2(0.29f, 0.77f);
				period = 6.6f;
				break;
			case "ShadowLadyCardArt":
				hue = new Color(1f, 0.22f, 0.78f);
				focus = new Vector2(0.68f, 0.89f);
				period = 7.4f;
				break;
			case "CubusSpikeArt":
				focus = new Vector2(0.68f, 0.14f);
				secondFocus = new Vector2(0.26f, 0.85f);
				pulseSpeed = 2.2f;
				break;
			case "DepressionWhisperArt":
				focus = new Vector2(0.4f, 0.73f);
				hue = new Color(0.52f, 0.48f, 1f);
				period = 8.8f;
				pulseSpeed = 0.85f;
				break;
			case "IllusionTwinsArt":
				hue = new Color(0.12f, 0.85f, 1f);
				focus = new Vector2(0.74f, 0.48f);
				secondFocus = new Vector2(0.72f, 0.22f);
				period = 7.8f;
				break;
			case "InsanityReachArt":
				hue = new Color(1f, 0.12f, 0.2f);
				focus = new Vector2(0.24f, 0.71f);
				secondFocus = new Vector2(0.77f, 0.67f);
				pulseSpeed = 1.8f;
				break;
			case "ParadoxTomeArt":
				hue = new Color(0.15f, 0.78f, 1f);
				focus = new Vector2(0.4f, 0.39f);
				secondFocus = new Vector2(0.73f, 0.35f);
				period = 6.8f;
				break;
			case "PlagueBoostArt":
				hue = new Color(0.43f, 1f, 0.12f);
				focus = new Vector2(0.84f, 0.32f);
				secondFocus = new Vector2(0.55f, 0.73f);
				period = 8.2f;
				pulseSpeed = 1.1f;
				break;
			case "AbyssPrincessCardArt":
				hue = new Color(1f, 0.14f, 0.7f);
				focus = new Vector2(0.79f, 0.5f);
				secondFocus = new Vector2(0.74f, 0.21f);
				period = 8f;
				break;
			case "ArroganceGhostCardArt":
				hue = new Color(1f, 0.26f, 0.89f);
				focus = new Vector2(0.49f, 0.51f);
				secondFocus = new Vector2(0.43f, 0.22f);
				period = 6.4f;
				break;
			case "EndlessShadowCardArt":
				focus = new Vector2(0.71f, 0.21f);
				secondFocus = new Vector2(0.27f, 0.51f);
				period = 8.6f;
				pulseSpeed = 1f;
				break;
			case "ShadowWarriorCardArt":
				focus = new Vector2(0.5f, 0.42f);
				secondFocus = new Vector2(0.24f, 0.61f);
				period = 7.2f;
				pulseSpeed = 1.7f;
				break;
			default:
				return false;
			}
			return true;
		}
	}
	public sealed class SuccChampionCardAnimation : MonoBehaviour
	{
		[SerializeField]
		private Image? portrait;

		[SerializeField]
		private SuccChampionCardAtmosphere? atmosphere;

		[SerializeField]
		private Vector3 originalScale;

		[SerializeField]
		private Vector2 originalPosition;

		[SerializeField]
		private float period;

		private float startTime;

		internal void Configure(Image image, SuccChampionCardAtmosphere overlay, float cycle)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			portrait = image;
			atmosphere = overlay;
			originalScale = ((Transform)((Graphic)image).rectTransform).localScale;
			originalPosition = ((Graphic)image).rectTransform.anchoredPosition;
			period = cycle;
			startTime = Time.unscaledTime;
		}

		private void OnEnable()
		{
			startTime = Time.unscaledTime;
		}

		private void LateUpdate()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)portrait == (Object)null) && !((Object)(object)((Graphic)portrait).canvas == (Object)null) && !((Graphic)portrait).canvasRenderer.cull)
			{
				float num = Time.unscaledTime - startTime;
				float num2 = num * (MathF.PI * 2f / Mathf.Max(1f, period));
				float num3 = Mathf.Sin(num2);
				float num4 = 1.028f + 0.008f * num3;
				RectTransform rectTransform = ((Graphic)portrait).rectTransform;
				((Transform)rectTransform).localScale = Vector3.Scale(originalScale, new Vector3(num4, num4, 1f));
				Vector2 val = originalPosition;
				float num5 = Mathf.Sin(num2 * 0.5f);
				Rect rect = rectTransform.rect;
				float num6 = num5 * ((Rect)(ref rect)).width * 0.003f;
				float num7 = Mathf.Cos(num2);
				rect = rectTransform.rect;
				rectTransform.anchoredPosition = val + new Vector2(num6, num7 * ((Rect)(ref rect)).height * 0.004f);
				if ((Object)(object)atmosphere != (Object)null)
				{
					((Graphic)atmosphere).color = ((Graphic)portrait).color;
				}
				atmosphere?.Advance(num);
			}
		}

		private void OnDisable()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)portrait == (Object)null))
			{
				((Transform)((Graphic)portrait).rectTransform).localScale = originalScale;
				((Graphic)portrait).rectTransform.anchoredPosition = originalPosition;
			}
		}
	}
	public sealed class SuccChampionCardAtmosphere : MaskableGraphic
	{
		[SerializeField]
		private Color glowColor;

		[SerializeField]
		private Vector2 focus;

		[SerializeField]
		private Vector2 secondFocus;

		[SerializeField]
		private float pulseSpeed;

		private float elapsed;

		internal void Configure(Color hue, Vector2 primary, Vector2 secondary, float speed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0009: 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)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			glowColor = hue;
			focus = primary;
			secondFocus = secondary;
			pulseSpeed = speed;
			((Graphic)this).SetVerticesDirty();
		}

		internal void Advance(float time)
		{
			elapsed = time;
			((Graphic)this).SetVerticesDirty();
		}

		protected override void OnPopulateMesh(VertexHelper mesh)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			//IL_0056: 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_0098: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			mesh.Clear();
			Rect rect = ((Graphic)this).rectTransform.rect;
			float num = Mathf.Min(((Rect)(ref rect)).width, ((Rect)(ref rect)).height);
			if (!(num <= 0f))
			{
				Color hue = glowColor;
				hue.r *= ((Graphic)this).color.r;
				hue.g *= ((Graphic)this).color.g;
				hue.b *= ((Graphic)this).color.b;
				float num2 = 0.5f + 0.5f * Mathf.Sin(elapsed * pulseSpeed);
				AddGlow(mesh, At(rect, focus.x, focus.y), num * (0.052f + num2 * 0.017f), hue, (0.12f + num2 * 0.1f) * ((Graphic)this).color.a);
				if (secondFocus.x >= 0f)
				{
					AddGlow(mesh, At(rect, secondFocus.x, secondFocus.y), num * (0.038f + (1f - num2) * 0.014f), hue, (0.1f + (1f - num2) * 0.08f) * ((Graphic)this).color.a);
				}
				for (int i = 0; i < 12; i++)
				{
					float num3 = Mathf.Repeat(elapsed * (0.1f + (float)(i % 3) * 0.015f) + (float)i * 0.137f, 1f);
					float x = ((i % 2 == 0) ? 0.13f : 0.87f) + 0.055f * Mathf.Sin(num3 * 2f * MathF.PI + (float)i * 2.1f);
					float y = 0.07f + num3 * 0.86f;
					float num4 = Mathf.Sin(num3 * MathF.PI);
					AddGlow(mesh, At(rect, x, y), num * (0.008f + (float)(i % 3) * 0.002f), hue, num4 * (0.22f + (float)(i % 2) * 0.12f) * ((Graphic)this).color.a);
				}
			}
		}

		private static Vector2 At(Rect area, float x, float y)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(((Rect)(ref area)).xMin + x * ((Rect)(ref area)).width, ((Rect)(ref area)).yMin + y * ((Rect)(ref area)).height);
		}

		private static void AddGlow(VertexHelper mesh, Vector2 center, float radius, Color hue, float alpha)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			int currentVertCount = mesh.currentVertCount;
			hue.a = alpha;
			mesh.AddVert(new Vector3(center.x, center.y, 0f), Color32.op_Implicit(hue), Vector4.op_Implicit(Vector2.zero));
			hue.a = 0f;
			for (int i = 0; i <= 16; i++)
			{
				float num = (float)i * 2f * MathF.PI / 16f;
				mesh.AddVert(new Vector3(center.x + Mathf.Cos(num) * radius, center.y + Mathf.Sin(num) * radius, 0f), Color32.op_Implicit(hue), Vector4.op_Implicit(Vector2.zero));
				if (i > 0)
				{
					mesh.AddTriangle(currentVertCount, currentVertCount + i, currentVertCount + i + 1);
				}
			}
		}
	}
	public sealed class CardEffectEndlessShadowRebirth : CardEffectBase
	{
		private const int HealthPenalty = 5;

		private readonly CardEffectSpawnMonster nativeSpawner = new CardEffectSpawnMonster();

		public override PropDescriptions CreateEditorInspectorDescriptions()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			return new PropDescriptions();
		}

		public override bool TestEffect(CardEffectState effect, CardEffectParams parameters, ICoreGameManagers core)
		{
			CharacterState selfTarget = parameters.selfTarget;
			if ((Object)(object)selfTarget == (Object)null || selfTarget.IsDestroyed || !selfTarget.IsDead)
			{
				return false;
			}
			float num;
			if (parameters.playedCard == null || effect.GetParamBool())
			{
				CharacterData paramCharacterData = effect.GetParamCharacterData();
				num = ((paramCharacterData != null) ? paramCharacterData.GetHealth() : 0);
			}
			else
			{
				num = parameters.playedCard.GetHealth();
			}
			if (num > 5f)
			{
				return ((CardEffectBase)nativeSpawner).TestEffect(effect, parameters, core);
			}
			return false;
		}

		public override IEnumerator ApplyEffect(CardEffectState effect, CardEffectParams parameters, ICoreGameManagers core, ISystemManagers systems)
		{
			if (!((CardEffectBase)this).TestEffect(effect, parameters, core))
			{
				yield break;
			}
			if (!core.GetSaveManager().PreviewMode)
			{
				yield return ((CardEffectBase)nativeSpawner).ApplyEffect(effect, parameters, core, systems);
				yield break;
			}
			EndlessShadowPreviewUpgrade.Scope scope = new EndlessShadowPreviewUpgrade.Scope(parameters.playedCard, effect.GetParamCardUpgradeData());
			EndlessShadowPreviewUpgrade.Scopes.Add(scope);
			try
			{
				yield return ((CardEffectBase)nativeSpawner).ApplyEffect(effect, parameters, core, systems);
			}
			finally
			{
				EndlessShadowPreviewUpgrade.Scopes.Remove(scope);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterState), "ApplyCardUpgrade")]
	internal static class EndlessShadowPreviewUpgrade
	{
		internal sealed class Scope
		{
			internal readonly CardState? Source;

			internal readonly CardUpgradeData? Upgrade;

			internal readonly HashSet<CardState> Recorded = new HashSet<CardState>();

			internal Scope(CardState? source, CardUpgradeData? upgrade)
			{
				Source = source;
				Upgrade = upgrade;
			}
		}

		internal static readonly List<Scope> Scopes = new List<Scope>();

		[HarmonyPrefix]
		internal static void Before(CharacterState __instance, CardUpgradeState cardUpgradeState, bool fromSpawn)
		{
			if (fromSpawn || (Object)(object)__instance == (Object)null || __instance.IsDestroyed || !__instance.PreviewMode || !__instance.SpawnedInPreviewMode)
			{
				return;
			}
			CardState spawnerCard = __instance.GetSpawnerCard();
			if (spawnerCard == null)
			{
				return;
			}
			for (int num = Scopes.Count - 1; num >= 0; num--)
			{
				Scope scope = Scopes[num];
				if (scope.Source != null && spawnerCard != scope.Source && !((Object)(object)scope.Upgrade == (Object)null) && !(cardUpgradeState.GetCardUpgradeDataId() != ((GameData)scope.Upgrade).GetID()))
				{
					if (scope.Recorded.Add(spawnerCard))
					{
						spawnerCard.GetTemporaryCardStateModifiers().AddUpgrade(cardUpgradeState, (CardStateModifiers)null);
					}
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(TargetHelper), "CollectTargets", new Type[]
	{
		typeof(CardEffectState),
		typeof(CardEffectParams),
		typeof(ICoreGameManagers),
		typeof(bool)
	})]
	internal static class SuccClanNonBossTargeting
	{
		[HarmonyPostfix]
		private static void AfterCollect(CardEffectState effectState, CardEffectParams cardEffectParams)
		{
			if (effectState != null && effectState.GetTargetIgnoreBosses() && SuccClanEffectContext.IsOwn(effectState, cardEffectParams))
			{
				cardEffectParams.targets?.RemoveAll(IsCompanionBoss);
				if (TargetHelper.LastTargetedCharacters is List<CharacterState> list)
				{
					list.RemoveAll(IsCompanionBoss);
				}
			}
		}

		private static bool IsCompanionBoss(CharacterState target)
		{
			if ((Object)(object)target != (Object)null)
			{
				if (!target.IsDestroyed)
				{
					return target.IsCompanionBoss();
				}
				return true;
			}
			return false;
		}
	}
	internal static class SuccClanBossTargetValidation
	{
		internal static bool Applies(CardEffectState effect)
		{
			if (effect != null && effect.GetTargetIgnoreBosses())
			{
				return SuccClanEffectContext.IsCard(effect.GetParentCardState());
			}
			return false;
		}

		internal static bool Invalid(CharacterState? target)
		{
			if (!((Object)(object)target == (Object)null) && !target.IsDestroyed && !target.IsAnyBoss())
			{
				return target.IsCompanionBoss();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TargetHelper), "CheckTargetsOverride")]
	internal static class SuccClanDropTargetBossPatch
	{
		[HarmonyPostfix]
		private static void After(CardEffectState effectState, List<CharacterState> targets)
		{
			if (SuccClanBossTargetValidation.Applies(effectState))
			{
				targets.RemoveAll(SuccClanBossTargetValidation.Invalid);
				if (TargetHelper.LastTargetedCharacters is List<CharacterState> list)
				{
					list.RemoveAll(SuccClanBossTargetValidation.Invalid);
				}
			}
		}
	}
	internal static class SuccClanEffectContext
	{
		internal static bool IsCard(CardState? card)
		{
			if (card == null)
			{
				return false;
			}
			ClassData clanInstance = Plugin.ClanInstance;
			if (!((Object)(object)clanInstance != (Object)null) || !(card.GetLinkedClassID() == ((GameData)clanInstance).GetID()))
			{
				string assetName = card.GetAssetName();
				if (assetName == null)
				{
					return false;
				}
				return StringExtensions.BelongsToMod(assetName, "mt2_succclan.Plugin", "Card");
			}
			return true;
		}

		internal static bool IsCharacter(CharacterState? unit)
		{
			if ((Object)(object)unit == (Object)null || unit.IsDestroyed)
			{
				return false;
			}
			if (!IsCard(unit.GetSpawnerCard()))
			{
				CharacterData sourceCharacterData = unit.GetSourceCharacterData();
				if (sourceCharacterData == null)
				{
					return false;
				}
				string assetKey = sourceCharacterData.GetAssetKey();
				return ((assetKey != null) ? new bool?(StringExtensions.BelongsToMod(assetKey, "mt2_succclan.Plugin", "Character")) : ((bool?)null)) == true;
			}
			return true;
		}

		internal static bool IsOwn(CardEffectState effect, CardEffectParams parameters)
		{
			if (!IsCard(effect.GetParentCardState()) && !IsCard(parameters.playedCard) && !IsCharacter(parameters.selfTarget))
			{
				return IsCharacter(parameters.characterThatActivatedAbility);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TargetHelper), "CollectTargets", new Type[]
	{
		typeof(CardEffectState),
		typeof(CardEffectParams),
		typeof(ICoreGameManagers),
		typeof(bool)
	})]
	internal static class SuccClanHandCardTargetsPatch
	{
		[HarmonyPrefix]
		private static bool Before(CardEffectState effectState, CardEffectParams cardEffectParams, ICoreGameManagers coreGameManagers)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (coreGameManagers == null || effectState == null || (int)effectState.GetTargetMode() != 18 || ((object)effectState.GetCardEffect())?.GetType().FullName != "Conductor.CardEffects.CardEffectRandomDiscardFromCardPile" || !SuccClanEffectContext.IsOwn(effectState, cardEffectParams))
			{
				return true;
			}
			cardEffectParams.targets.Clear();
			cardEffectParams.targetCards.Clear();
			cardEffectParams.targetCards.AddRange(coreGameManagers.GetCardManager().GetHand(false));
			return false;
		}
	}
	internal static class LastWhisperTooltips
	{
		internal const string TitleKey = "mt2_succclan_LastWhisper_Accursed_Title";

		internal static IEnumerable<TooltipContent> Rewrite(IEnumerable<TooltipContent> original, CardEffectData data)
		{
			//IL_003b: 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)
			if (data == null || data.GetAdditionalTooltips() == null || !data.GetAdditionalTooltips().Any((AdditionalTooltipData t) => t != null && t.titleKey == "mt2_succclan_LastWhisper_Accursed_Title"))
			{
				return original;
			}
			return WithoutNativeTrigger(original, ((object)data.GetParamTrigger()/*cast due to .constrained prefix*/).ToString());
		}

		private static IEnumerable<TooltipContent> WithoutNativeTrigger(IEnumerable<TooltipContent> original, string nativeTriggerId)
		{
			foreach (TooltipContent item in original)
			{
				if (item.tooltipId != nativeTriggerId)
				{
					yield return item;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CardTooltipHelper), "GetCardEffectTooltipContents", new Type[]
	{
		typeof(CardEffectData),
		typeof(SaveManager)
	})]
	internal static class LastWhisperDataTooltipPatch
	{
		private static void Postfix(CardEffectData cardEffectData, ref IEnumerable<TooltipContent> __result)
		{
			__result = LastWhisperTooltips.Rewrite(__result, cardEffectData);
		}
	}
	[HarmonyPatch(typeof(CardTooltipHelper), "GetCardEffectTooltipContents", new Type[]
	{
		typeof(CardEffectState),
		typeof(TitleStyle),
		typeof(SaveManager)
	})]
	internal static class LastWhisperStateTooltipPatch
	{
		private static void Postfix(CardEffectState cardEffectState, ref IEnumerable<TooltipContent> __result)
		{
			__result = LastWhisperTooltips.Rewrite(__result, cardEffectState.GetSourceCardEffectData());
		}
	}
}