Decompiled source of DeathcardChallenges v1.0.1

DeathcardChallenges.dll

Decompiled 10 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DiskCardGame;
using HarmonyLib;
using InscryptionAPI.Ascension;
using InscryptionAPI.Card;
using InscryptionAPI.CardCosts;
using InscryptionAPI.Helpers;
using Microsoft.CodeAnalysis;
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 = ".NET Standard 2.0")]
[assembly: AssemblyCompany("DeathcardChallenges")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds deathcard challenges")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("DeathcardChallenges")]
[assembly: AssemblyTitle("DeathcardChallenges")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 DeathcardChallenges
{
	[BepInPlugin("tvflabs.inscryption.deathcardchallenges", "DeathcardChallenges", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(SaveFile), "GetChoosableDeathcardMods")]
		private class AvailableDeathcardsPatch
		{
			private static void Postfix(ref List<CardModificationInfo> __result, SaveFile __instance)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: 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_0101: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_015c: Unknown result type (might be due to invalid IL or missing references)
				if (!SaveFile.IsAscension || !AscensionSaveData.Data.ChallengeIsActive(UseDeathcard.Challenge.challengeType))
				{
					return;
				}
				List<CardModificationInfo> list = new List<CardModificationInfo>(__instance.deathCardMods);
				List<CardModificationInfo> toBeRemoved = new List<CardModificationInfo>();
				list.RemoveAll((CardModificationInfo x) => ((CardCollectionInfo)RunState.Run.playerDeck).Cards.Exists((CardInfo d) => d.DisplayedNameEnglish == x.nameReplacement));
				foreach (CardModificationInfo item in list)
				{
					foreach (Ability ability in item.abilities)
					{
						if (AbilityExtensions.AbilityByID((IEnumerable<FullAbility>)AbilityManager.AllAbilities, ability) == null)
						{
							toBeRemoved.Add(item);
						}
					}
					foreach (Ability negateAbility in item.negateAbilities)
					{
						if (AbilityExtensions.AbilityByID((IEnumerable<FullAbility>)AbilityManager.AllAbilities, negateAbility) == null)
						{
							toBeRemoved.Add(item);
						}
					}
					foreach (SpecialTriggeredAbility specialAbility in item.specialAbilities)
					{
						if (AbilityExtensions.AbilityByID((IEnumerable<FullAbility>)AbilityManager.AllAbilities, (Ability)specialAbility) == null)
						{
							toBeRemoved.Add(item);
						}
					}
					foreach (FullCardCost item2 in CardModificationInfoExtensions.GetCustomCostsFromMod(item))
					{
						if (item2 == null)
						{
							toBeRemoved.Add(item);
						}
					}
				}
				list.RemoveAll((CardModificationInfo x) => toBeRemoved.Contains(x));
				__result = list;
			}
		}

		[HarmonyPatch(typeof(Part1GameFlowManager), "KillPlayerSequence")]
		private class DeathPatch
		{
			private static IEnumerator Postfix(IEnumerator values)
			{
				while (values.MoveNext())
				{
					yield return values.Current;
				}
				if (SaveFile.IsAscension && AscensionSaveData.Data.ChallengeIsActive(MakeDeathcard.Challenge.challengeType))
				{
					SceneLoader.Load("Part1_Sanctum");
				}
			}
		}

		[HarmonyPatch(typeof(SanctumSceneSequencer), "DeathCardSequence")]
		private class PhotoEndRunPatch
		{
			private static IEnumerator Postfix(IEnumerator values)
			{
				while (values.MoveNext())
				{
					yield return values.Current;
				}
				if (SaveFile.IsAscension)
				{
					AscensionMenuScreens.ReturningFromFailedRun = true;
					AscensionStatsData.TryIncrementStat((Type)1);
					SaveManager.SaveToFile(true);
					SceneLoader.Load("Ascension_Configure");
				}
			}
		}

		[HarmonyPatch(typeof(SanctumSceneSequencer), "IntroSequence")]
		private class ShowDeathcardChallengeUIAtDeathPatch
		{
			private static IEnumerator Postfix(IEnumerator values, SanctumSceneSequencer __instance)
			{
				if (SaveFile.IsAscension && AscensionSaveData.Data.ChallengeIsActive(MakeDeathcard.Challenge.challengeType))
				{
					Singleton<ChallengeActivationUI>.Instance.ShowActivation(MakeDeathcard.Challenge.challengeType);
				}
				while (values.MoveNext())
				{
					yield return values.Current;
				}
			}
		}

		[HarmonyPatch(typeof(CardSingleChoicesSequencer), "OnCardFlipped")]
		private class ShowDeathcardChallengeUIAtChoicePatch
		{
			private static void Postfix(SelectableCard card, CardSingleChoicesSequencer __instance)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)((Card)card).Info != (Object)null && ((Object)((Card)card).Info).name == "!DEATHCARD_BASE" && SaveFile.IsAscension && AscensionSaveData.Data.ChallengeIsActive(UseDeathcard.Challenge.challengeType))
				{
					Singleton<ChallengeActivationUI>.Instance.ShowActivation(UseDeathcard.Challenge.challengeType);
				}
			}
		}

		private Harmony harmony = new Harmony("tvflabs.inscryption.deathcardchallenges");

		private const string PluginGuid = "tvflabs.inscryption.deathcardchallenges";

		private const string PluginName = "DeathcardChallenges";

		private const string PluginVersion = "1.0.1";

		private const string PluginPrefix = "DeathcardChallenges";

		private static FullChallenge UseDeathcard = ChallengeManager.Add("tvflabs.inscryption.deathcardchallenges", "Deathcards", "You may find past challengers' deathcards during your run", -20, TextureHelper.GetImageAsTexture("Deathcards.png", (FilterMode)0), TextureHelper.GetImageAsTexture("Deathcards_a.png", (FilterMode)0), 0, false);

		private static FullChallenge MakeDeathcard = ChallengeManager.Add("tvflabs.inscryption.deathcardchallenges", "Deathcard Creation", "You will create a deathcard if you lose", 0, TextureHelper.GetImageAsTexture("DeathcardCreation.png", (FilterMode)0), TextureHelper.GetImageAsTexture("DeathcardCreation_a.png", (FilterMode)0), 0, false);

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded DeathcardChallenges!");
			harmony.PatchAll();
			if (!AscensionStoryAndProgressFlags.MECHANICS_LEARNED.Contains((MechanicsConcept)60))
			{
				AscensionStoryAndProgressFlags.MECHANICS_LEARNED.Add((MechanicsConcept)60);
			}
			if (!AscensionStoryAndProgressFlags.STORY_EVENTS.Contains((StoryEvent)28))
			{
				AscensionStoryAndProgressFlags.STORY_EVENTS.Add((StoryEvent)28);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DeathcardChallenges";

		public const string PLUGIN_NAME = "DeathcardChallenges";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}