using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BanishCards.Runtime;
using BanishCards.Style;
using BanishCards.Utility;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[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("BanishCards")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+09eebf653d69b69dec92cbb74b2a550a0c0261e3")]
[assembly: AssemblyProduct("BanishCards")]
[assembly: AssemblyTitle("BanishCards")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BanishCards
{
[BepInPlugin("AgusBut.BanishCards", "BanishCards", "1.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal int BanishesThisRun = 0;
public static Plugin Instance { get; private set; }
public static ManualLogSource Log { get; private set; }
private void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
ConfigManager.Initialize((BaseUnityPlugin)(object)this);
SceneManager.activeSceneChanged += OnActiveSceneChanged;
Harmony val = new Harmony("AgusBut.BanishCards");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"BanishCards loaded successfully.");
}
private void OnActiveSceneChanged(Scene oldScene, Scene newScene)
{
if (((Scene)(ref newScene)).name == "GameScene")
{
BanishesThisRun = 0;
BanishedCards.BanishedUnlockNames.Clear();
}
}
}
}
namespace BanishCards.Utility
{
internal class ColorsHelper
{
public static Color Black = new Color(0.196f, 0.196f, 0.196f, 1f);
public static Color Grey = new Color(0.514f, 0.502f, 0.514f, 1f);
public static Color White = new Color(1f, 1f, 1f, 1f);
public static Color Green = new Color(0.635f, 0.741f, 0.451f, 1f);
public static Color DeepGreen = new Color(0.259f, 0.403f, 0.155f, 1f);
public static Color Blue = new Color(0.471f, 0.529f, 0.667f, 1f);
public static Color DeepBlue = new Color(0f, 0f, 0.286f, 1f);
public static Color Red = new Color(0.667f, 0.333f, 0.251f, 1f);
public static Color DeepRed = new Color(0.323f, 0.054f, 0.05f, 1f);
public static Color Purple = new Color(0.46f, 0.093f, 0.903f, 1f);
public static Color DeepPurple = new Color(0.369f, 0.157f, 0.569f, 1f);
public static Color Orange = new Color(0.544f, 0.411f, 0.265f, 1f);
public static Color DeepOrange = new Color(0.612f, 0.478f, 0.208f, 1f);
public static Color GetContrastByName(string colorName)
{
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: 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)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
return (Color)(colorName.ToLower() switch
{
"blue" => DeepBlue,
"deepblue" => Blue,
"red" => DeepRed,
"deepred" => Red,
"green" => DeepGreen,
"deepgreen" => Green,
"purple" => DeepPurple,
"deeppurple" => Purple,
"orange" => DeepOrange,
"deeporange" => Orange,
"black" => Grey,
"grey" => Black,
"white" => Grey,
_ => Grey,
});
}
}
internal static class ConfigManager
{
internal static ConfigEntry<int> MaxBanishesConfig;
internal static ConfigEntry<string> ButtonColor;
internal static void Initialize(BaseUnityPlugin plugin)
{
string text = "Can be: White, Grey, Black, Blue, Orange, Red, Green, Purple, DeepBlue, DeepBrown, DeepRed, DeepGreen, DeepPurple";
MaxBanishesConfig = plugin.Config.Bind<int>("General", "MaxBanishes", 3, "Maximum number of cards you can banish per run.");
ButtonColor = plugin.Config.Bind<string>("Appearance", "ButtonColor", "Grey", text);
}
}
internal class SpriteHelper
{
private static readonly Dictionary<string, Sprite> _spriteCache = new Dictionary<string, Sprite>();
internal static Sprite FindSpriteByName(string spriteName)
{
if (_spriteCache.TryGetValue(spriteName, out var value))
{
return value;
}
Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
foreach (Sprite val in array)
{
if (((Object)val).name == spriteName)
{
_spriteCache[spriteName] = val;
return val;
}
}
return null;
}
}
}
namespace BanishCards.Style
{
internal class SliceColor
{
internal static string GetPanelSlice(StyleManager.StyleType type)
{
if (type == StyleManager.StyleType.Button)
{
return "UI9Slice" + ConfigManager.ButtonColor.Value;
}
return "UI9SliceRed";
}
}
internal class StyleManager
{
public enum StyleType
{
Button
}
internal struct PanelVisualStyle
{
public string Slice;
public Color TextColor;
}
internal static PanelVisualStyle GetPanelStyle(StyleType type)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
PanelVisualStyle result = default(PanelVisualStyle);
result.Slice = SliceColor.GetPanelSlice(type);
result.TextColor = TextColor.GetCardTextColor(type);
return result;
}
}
internal class TextColor
{
internal static Color GetCardTextColor(StyleManager.StyleType type)
{
//IL_0021: 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_0029: Unknown result type (might be due to invalid IL or missing references)
string colorName = ((type != 0) ? "Grey" : ConfigManager.ButtonColor.Value);
return ColorsHelper.GetContrastByName(colorName);
}
}
}
namespace BanishCards.Runtime
{
public class BanishButtonCreation : MonoBehaviour
{
private Button button;
private Image buttonImage;
private Text buttonText;
private void Awake()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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)
button = ((Component)this).GetComponent<Button>();
buttonImage = ((Component)this).GetComponent<Image>();
buttonText = ((Component)this).GetComponentInChildren<Text>();
StyleManager.PanelVisualStyle panelStyle = StyleManager.GetPanelStyle(StyleManager.StyleType.Button);
if ((Object)(object)buttonImage != (Object)null)
{
buttonImage.sprite = SpriteHelper.FindSpriteByName(panelStyle.Slice + "Filled");
}
if ((Object)(object)button != (Object)null)
{
SpriteState spriteState = ((Selectable)button).spriteState;
((SpriteState)(ref spriteState)).highlightedSprite = SpriteHelper.FindSpriteByName(panelStyle.Slice);
((Selectable)button).spriteState = spriteState;
}
}
private void OnEnable()
{
UpdateState();
}
public void UpdateState()
{
//IL_00c8: 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_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
int value = ConfigManager.MaxBanishesConfig.Value;
int banishesThisRun = Plugin.Instance.BanishesThisRun;
FieldInfo fieldInfo = AccessTools.Field(typeof(CardManager), "cards");
UpgradeCard[] array = (UpgradeCard[])fieldInfo.GetValue(CardManager.instance);
int num = 0;
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null)
{
num++;
}
}
int num2 = num - 1;
int num3 = value - banishesThisRun;
Mathf.Min(num3, num2);
bool flag = banishesThisRun >= value;
bool flag2 = num <= 1 && !flag;
((Selectable)button).interactable = !(flag || flag2);
if ((Object)(object)buttonImage != (Object)null)
{
Color color = ((Graphic)buttonImage).color;
color.a = (flag ? 0f : (flag2 ? 0.3f : 1f));
((Graphic)buttonImage).color = color;
}
if ((Object)(object)buttonText != (Object)null)
{
Color textColor = StyleManager.GetPanelStyle(StyleManager.StyleType.Button).TextColor;
textColor.a = (flag ? 0f : (flag2 ? 0.3f : 1f));
((Graphic)buttonText).color = textColor;
}
((Component)this).gameObject.SetActive(!flag);
}
}
internal class BanishedCards
{
public static readonly List<string> BanishedUnlockNames = new List<string>();
}
internal class CardBanishManager
{
public static class UIRefreshHelper
{
public static void ForceRefreshCanvas()
{
GameObject val = GameObject.Find("CardUI/Canvas");
if ((Object)(object)val != (Object)null)
{
val.SetActive(false);
val.SetActive(true);
}
}
}
internal static void BanishCard(CardManager cardManager, int index)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(CardManager), "cards");
UpgradeCard[] array = (UpgradeCard[])fieldInfo.GetValue(cardManager);
int num = 0;
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null)
{
num++;
}
}
int value = ConfigManager.MaxBanishesConfig.Value;
int num2 = value - Plugin.Instance.BanishesThisRun;
int num3 = num - 1;
int num4 = Mathf.Min(num2, num3);
if (num4 <= 0)
{
return;
}
FieldInfo fieldInfo2 = AccessTools.Field(typeof(CardManager), "availableCards");
List<UpgradeCard> list = (List<UpgradeCard>)fieldInfo2.GetValue(cardManager);
FieldInfo fieldInfo3 = AccessTools.Field(typeof(CardManager), "cardHolders");
GameObject[] array2 = (GameObject[])fieldInfo3.GetValue(cardManager);
if (array == null || index >= array.Length)
{
return;
}
UpgradeCard val = array[index];
if ((Object)(object)val == (Object)null)
{
return;
}
string text = (string)AccessTools.Field(typeof(UpgradeCard), "unlockName").GetValue(val);
if (!string.IsNullOrEmpty(text))
{
BanishedCards.BanishedUnlockNames.Add(text);
}
Plugin.Instance.BanishesThisRun++;
if (list.Contains(val))
{
list.Remove(val);
}
int num5 = 0;
for (int j = 0; j < array.Length; j++)
{
if ((Object)(object)array[j] != (Object)null)
{
num5++;
}
}
for (int k = index; k < num5 - 1; k++)
{
array[k] = array[k + 1];
}
array[num5 - 1] = null;
array2[num5 - 1].SetActive(false);
FieldInfo fieldInfo4 = AccessTools.Field(typeof(CardManager), "titles");
FieldInfo fieldInfo5 = AccessTools.Field(typeof(CardManager), "images");
FieldInfo fieldInfo6 = AccessTools.Field(typeof(CardManager), "descriptions");
Text[] array3 = (Text[])fieldInfo4.GetValue(cardManager);
Image[] array4 = (Image[])fieldInfo5.GetValue(cardManager);
Text[] array5 = (Text[])fieldInfo6.GetValue(cardManager);
for (int l = index; l < num5 - 1; l++)
{
if ((Object)(object)array[l] != (Object)null)
{
array3[l].text = array[l].title;
array4[l].sprite = array[l].image;
array5[l].text = array[l].description;
}
}
array3[num5 - 1].text = "";
array4[num5 - 1].sprite = null;
array5[num5 - 1].text = "";
UIRefreshHelper.ForceRefreshCanvas();
}
}
}
namespace BanishCards.Patches
{
[HarmonyPatch(typeof(CardManager), "DisplayCards")]
internal class Patch_DisplayCards
{
private static void Postfix(CardManager __instance, int count)
{
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Expected O, but got Unknown
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
FieldInfo fieldInfo = AccessTools.Field(typeof(CardManager), "cardHolders");
GameObject[] array = (GameObject[])fieldInfo.GetValue(__instance);
for (int i = 0; i < count; i++)
{
try
{
Transform transform = array[i].transform;
Transform val = transform.Find($"Highlight{i}") ?? transform.Find("Highlight");
if ((Object)(object)val == (Object)null)
{
continue;
}
Transform val2 = val.Find("SelectButton");
if ((Object)(object)val2 == (Object)null)
{
continue;
}
Button component = ((Component)val2).GetComponent<Button>();
if (!((Object)(object)component == (Object)null))
{
GameObject val3 = Object.Instantiate<GameObject>(((Component)component).gameObject, val);
((Object)val3).name = "BanishButton";
val3.transform.localScale = Vector3.one;
val3.transform.localPosition = new Vector3(0f, 135f, 0f);
val3.transform.SetAsLastSibling();
Button component2 = val3.GetComponent<Button>();
if ((Object)(object)component2 != (Object)null)
{
Object.DestroyImmediate((Object)(object)component2);
}
Button val4 = val3.AddComponent<Button>();
((Selectable)val4).transition = ((Selectable)component).transition;
((Selectable)val4).colors = ((Selectable)component).colors;
Navigation navigation = default(Navigation);
((Navigation)(ref navigation)).mode = (Mode)0;
((Selectable)val4).navigation = navigation;
Image component3 = val3.GetComponent<Image>();
Image component4 = ((Component)component).GetComponent<Image>();
component3.sprite = component4.sprite;
component3.type = component4.type;
((Graphic)component3).color = ((Graphic)component4).color;
((Graphic)component3).raycastTarget = true;
((Selectable)val4).targetGraphic = (Graphic)(object)component3;
Text componentInChildren = val3.GetComponentInChildren<Text>();
Text componentInChildren2 = ((Component)component).GetComponentInChildren<Text>();
if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren2 != (Object)null)
{
componentInChildren.text = "Banish";
componentInChildren.font = componentInChildren2.font;
componentInChildren.fontSize = componentInChildren2.fontSize;
((Graphic)componentInChildren).color = ((Graphic)componentInChildren2).color;
componentInChildren.alignment = componentInChildren2.alignment;
componentInChildren.resizeTextForBestFit = componentInChildren2.resizeTextForBestFit;
componentInChildren.resizeTextMinSize = componentInChildren2.resizeTextMinSize;
componentInChildren.resizeTextMaxSize = componentInChildren2.resizeTextMaxSize;
}
int capturedIndex = i;
((UnityEvent)val4.onClick).AddListener((UnityAction)delegate
{
CardBanishManager.BanishCard(__instance, capturedIndex);
});
val3.AddComponent<BanishButtonCreation>();
val3.SetActive(true);
}
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Error creating banish button for card {i}: {arg}");
}
}
}
}
}