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 GBC;
using HarmonyLib;
using InscryptionAPI.Card;
using InscryptionAPI.Helpers;
using InscryptionCommunityPatch.Card;
using Sirenix.Serialization.Utilities;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ArasCosts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ArasCosts")]
[assembly: AssemblyTitle("ArasCosts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ArasCosts;
[HarmonyPatch]
public class CostPatches
{
public static bool CheckOvercharge(int amnt, CardInfo inf)
{
return Singleton<ResourcesManager>.Instance.PlayerMaxEnergy >= amnt;
}
public static bool CheckPrism(int amnt, CardInfo inf)
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected I4, but got Unknown
int num = 0;
foreach (CardSlot item in Singleton<BoardManager>.Instance.PlayerSlotsCopy)
{
if ((Object)(object)item.Card != (Object)null && CardExtensions.HasTrait(item.Card, (Trait)17))
{
num++;
}
}
foreach (GemType item2 in inf.GemsCost)
{
GemType val = item2;
GemType val2 = val;
switch ((int)val2)
{
case 0:
foreach (CardSlot item3 in Singleton<BoardManager>.Instance.PlayerSlotsCopy)
{
if ((Object)(object)item3.Card != (Object)null && item3.Card.HasAbility((Ability)37))
{
num--;
break;
}
}
break;
case 1:
foreach (CardSlot item4 in Singleton<BoardManager>.Instance.PlayerSlotsCopy)
{
if ((Object)(object)item4.Card != (Object)null && item4.Card.HasAbility((Ability)38))
{
num--;
break;
}
}
break;
case 2:
foreach (CardSlot item5 in Singleton<BoardManager>.Instance.PlayerSlotsCopy)
{
if ((Object)(object)item5.Card != (Object)null && item5.Card.HasAbility((Ability)39))
{
num--;
break;
}
}
break;
}
}
Plugin.Log.LogInfo((object)("Prism Amount Calculated: " + num));
return num >= amnt;
}
[HarmonyPatch(typeof(PlayableCard), "CanPlay")]
[HarmonyPostfix]
public static void IsCustomCostMet(ref bool __result, ref PlayableCard __instance)
{
if (CardExtensions.GetExtendedPropertyAsInt(((Card)__instance).Info, "PrismCost") > 0)
{
bool flag = CheckPrism(CardExtensions.GetExtendedPropertyAsInt(((Card)__instance).Info, "PrismCost").GetValueOrDefault(), ((Card)__instance).Info);
bool flag2 = CheckPrism(CardExtensions.GetExtendedPropertyAsInt(((Card)__instance).Info, "OverchargeCost").GetValueOrDefault(), ((Card)__instance).Info);
if (__result && flag && flag2)
{
__result = true;
}
else
{
__result = false;
}
}
}
[HarmonyPatch(typeof(PlayerHand), "PlayCardOnSlot")]
[HarmonyPostfix]
public static IEnumerator PayCustomCost(IEnumerator enumerator, PlayerHand __instance, PlayableCard card)
{
if (CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "OverchargeCost") > 0)
{
((MonoBehaviour)CustomCoroutine.Instance).StartCoroutine(TakeMaxEnergy(card));
}
yield return enumerator;
}
private static IEnumerator TakeMaxEnergy(PlayableCard card)
{
yield return (object)new WaitForSeconds(0.35f);
yield return ResourcesManagerHelpers.RemoveMaxEnergy(Singleton<ResourcesManager>.Instance, CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "OverchargeCost").Value);
}
[HarmonyPatch(typeof(HintsHandler), "OnNonplayableCardClicked")]
[HarmonyPostfix]
public static void ExampleCostCannotAffordHint(ref PlayableCard card)
{
if (CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "PrismCost") > 0 && !CheckPrism(CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "PrismCost").GetValueOrDefault(), ((Card)card).Info))
{
if (UnityExtensions.SafeIsUnityNull((Object)(object)Singleton<BoardManager>.Instance))
{
((MonoBehaviour)CustomCoroutine.Instance).StartCoroutine(Singleton<TextDisplayer>.Instance.ShowUntilInput("You dont have enough Gems on the Board...", -2.5f, 0.5f, (Emotion)0, (LetterAnimation)0, (Speaker)0, (string[])null, true));
}
else
{
((MonoBehaviour)CustomCoroutine.Instance).StartCoroutine(Singleton<TextBox>.Instance.ShowUntilInput("You dont have enough Gems on the Board", (Style)4, (DialogueSpeaker)null, (ScreenPosition)0, 0f, true, false, (Prompt)null, true, (Emotion)0));
}
}
if (CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "OverchargeCost") > 0 && !CheckOvercharge(CardExtensions.GetExtendedPropertyAsInt(((Card)card).Info, "OverchargeCost").GetValueOrDefault(), ((Card)card).Info))
{
if (UnityExtensions.SafeIsUnityNull((Object)(object)Singleton<BoardManager>.Instance))
{
((MonoBehaviour)CustomCoroutine.Instance).StartCoroutine(Singleton<TextDisplayer>.Instance.ShowUntilInput("You dont have enough Gems on the Maximum Energy Cells...", -2.5f, 0.5f, (Emotion)0, (LetterAnimation)0, (Speaker)0, (string[])null, true));
}
else
{
((MonoBehaviour)CustomCoroutine.Instance).StartCoroutine(Singleton<TextBox>.Instance.ShowUntilInput("You dont have enough Maximum Energy Cells", (Style)4, (DialogueSpeaker)null, (ScreenPosition)0, 0f, true, false, (Prompt)null, true, (Emotion)0));
}
}
}
}
public class Overcharge
{
public static void AddOvercharge()
{
Part1CardCostRender.UpdateCardCost += delegate(CardInfo card, List<Texture2D> costs)
{
int valueOrDefault2 = CardExtensions.GetExtendedPropertyAsInt(card, "OverchargeCost").GetValueOrDefault();
if (valueOrDefault2 > 0)
{
costs.Add(Tools.LoadTex($"ArasCosts/Artwork/Cards/Costs/{valueOrDefault2}Overcharge.png"));
}
};
Part2CardCostRender.UpdateCardCost += delegate(CardInfo card, List<Texture2D> costs)
{
int valueOrDefault = CardExtensions.GetExtendedPropertyAsInt(card, "OverchargeCost").GetValueOrDefault();
if (valueOrDefault > 0)
{
costs.Add(Tools.LoadTex($"ArasCosts/Artwork/Cards/Costs/{valueOrDefault}OverchargePixel.png"));
}
};
}
}
public class Prism
{
public static void AddPrism()
{
Part1CardCostRender.UpdateCardCost += delegate(CardInfo card, List<Texture2D> costs)
{
int valueOrDefault2 = CardExtensions.GetExtendedPropertyAsInt(card, "PrismCost").GetValueOrDefault();
if (valueOrDefault2 > 0)
{
costs.Add(Tools.LoadTex($"ArasCosts/Artwork/Cards/Costs/{valueOrDefault2}Prism.png"));
}
};
Part2CardCostRender.UpdateCardCost += delegate(CardInfo card, List<Texture2D> costs)
{
int valueOrDefault = CardExtensions.GetExtendedPropertyAsInt(card, "PrismCost").GetValueOrDefault();
if (valueOrDefault > 0)
{
costs.Add(Tools.LoadTex($"ArasCosts/Artwork/Cards/Costs/{valueOrDefault}PrismPixel.png"));
}
};
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("arackulele.inscryption.ArasCosts", "Aras Costs", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "arackulele.inscryption.ArasCosts";
public const string Name = "Aras Costs";
private const string Version = "1.0.0";
internal static ManualLogSource Log;
private static Harmony _harmony;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"[Plugin] Loading patches...");
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "arackulele.inscryption.ArasCosts");
Log.LogInfo((object)"[Plugin] Done patches...");
Prism.AddPrism();
Overcharge.AddOvercharge();
Log.LogInfo((object)"[Plugin] Initialized");
}
private void Update()
{
}
}
public static class Tools
{
public static CardInfo GetCardInfo(this string self)
{
return CardManager.AllCardsCopy.Single((CardInfo info) => ((Object)info).name == self);
}
public static Texture2D LoadTex(string path)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
byte[] array = ExtractEmbeddedResource(path);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
((Texture)val).filterMode = (FilterMode)0;
return val;
}
public static Sprite LoadSprite(string path)
{
Texture2D tex = LoadTex(path);
return ConvertTexToSprite(tex);
}
public static Sprite ConvertTexToSprite(Texture2D tex, Vector2? pivot = null)
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
Vector2 val = default(Vector2);
((Vector2)(ref val))..ctor(0.5f, 0.5f);
if (pivot.HasValue)
{
((Vector2)(ref val))..ctor(pivot.Value.x, pivot.Value.y);
}
((Texture)tex).filterMode = (FilterMode)0;
return Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), val, 100f);
}
public static Sprite GenerateAct2Portrait(Texture2D tex)
{
//IL_0022: 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)
((Texture)tex).filterMode = (FilterMode)0;
return Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f), 100f);
}
public static byte[] ExtractEmbeddedResource(string filePath)
{
filePath = filePath.Replace("/", ".");
filePath = filePath.Replace("\\", ".");
Assembly callingAssembly = Assembly.GetCallingAssembly();
using Stream stream = callingAssembly.GetManifestResourceStream(filePath);
if (stream == null)
{
return null;
}
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
return array;
}
}