Decompiled source of Chaotic Corruptions v1.1.1

BepInEx/plugins/com.binbin.ChaoticCorruptions.dll

Decompiled a day 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 BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cards;
using Cards.Data;
using Cards.Utility;
using ChaoticCorruptions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Obeliskial_Essentials;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.binbin.ChaoticCorruptions")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+14f4bbdffb35d0c0e6bb6178030a9b06e32bbb3c")]
[assembly: AssemblyProduct("ChaoticCorruptions")]
[assembly: AssemblyTitle("com.binbin.ChaoticCorruptions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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;
		}
	}
}
public static class EssentialsCompatibility
{
	private static bool? _enabled;

	public static bool Enabled
	{
		get
		{
			bool valueOrDefault = _enabled == true;
			if (!_enabled.HasValue)
			{
				valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.stiffmeds.obeliskialessentials");
				_enabled = valueOrDefault;
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void EssentialsRegister()
	{
		Essentials.RegisterMod(Plugin.PluginName, "binbin", "Provides configs to Randomize or Corrupt starter cards and items.", Plugin.PluginVersion, Plugin.ModDate, "https://github.com/binbinmods/ChaoticCorruptions", (string[])null, "", 100, (string[])null, "", true);
		Plugin.LogInfo(Plugin.PluginGUID + " " + Plugin.PluginVersion + " has loaded with Essentials!");
	}
}
namespace ChaoticCorruptions
{
	[HarmonyPatch]
	public class AntiCheat
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScore")]
		public static bool SetObeliskScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScore")]
		public static bool SetScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScore")]
		public static bool SetSingularityScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScoreLeaderboard")]
		public static bool SetObeliskScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScoreLeaderboard")]
		public static bool SetScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScoreLeaderboard")]
		public static bool SetSingularityScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScore")]
		public static bool SetWeeklyScorePrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScoreLeaderboard")]
		public static bool SetWeeklyScoreLeaderboardPrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}
	}
	public class ChaoticCorruptionsFunctions
	{
		public static CardRealtimeData GetRandomCardWeighted(Hero hero, bool craftableOnly = true)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00bf: 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_00cc: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Invalid comparison between Unknown and I4
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Invalid comparison between Unknown and I4
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Invalid comparison between Unknown and I4
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Invalid comparison between Unknown and I4
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Invalid comparison between Unknown and I4
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Invalid comparison between Unknown and I4
			AtOManager instance = AtOManager.Instance;
			int num = ((instance != null) ? instance.GetNgPlus(false) : 0);
			int num2 = ((!craftableOnly) ? 30 : ((num < 5) ? 10 : 37));
			int num3 = ((!craftableOnly) ? 35 : ((num < 5) ? 65 : 60));
			int num4 = ((!craftableOnly) ? 20 : ((num < 5) ? 20 : 3));
			int num5 = ((!craftableOnly) ? 10 : ((num < 5) ? 5 : 0));
			CardClass result = (CardClass)11;
			Enum.TryParse<CardClass>(Enum.GetName(typeof(HeroClass), ((Character)hero).HeroData.HeroClass), out result);
			CardClass result2 = (CardClass)11;
			Enum.TryParse<CardClass>(Enum.GetName(typeof(HeroClass), ((Character)hero).HeroData.HeroSubClass.HeroClassSecondary), out result2);
			List<string> list = Globals.Instance.CardListNotUpgradedByClass[result];
			List<string> list2 = (((int)result2 == 11) ? new List<string>() : Globals.Instance.CardListNotUpgradedByClass[result2]);
			int num6 = Random.Range(0, 2);
			int num7 = Random.Range(0, 100);
			CardRealtimeData cardData = Globals.Instance.GetCardData((num6 < 1 || (int)result2 == 11) ? list[Random.Range(0, list.Count)] : list2[Random.Range(0, list2.Count)], false);
			Plugin.LogDebug("Randomizing card: " + cardData.Id, "GetRandomCardWeighted");
			bool flag = true;
			while (flag)
			{
				flag = false;
				bool flag2 = false;
				while (!flag2)
				{
					flag = false;
					cardData = Globals.Instance.GetCardData((num6 < 1 || (int)result2 == 11) ? list[Random.Range(0, list.Count)] : list2[Random.Range(0, list2.Count)], false);
					if (flag)
					{
						continue;
					}
					if (num7 < num2)
					{
						if ((int)cardData.CardRarity == 0)
						{
							flag2 = true;
						}
					}
					else if (num7 < num2 + num3)
					{
						if ((int)cardData.CardRarity == 1)
						{
							flag2 = true;
						}
					}
					else if (num7 < num2 + num3 + num4)
					{
						if ((int)cardData.CardRarity == 2)
						{
							flag2 = true;
						}
					}
					else if (num7 < num2 + num3 + num4 + num5)
					{
						if ((int)cardData.CardRarity == 3)
						{
							flag2 = true;
						}
					}
					else if ((int)cardData.CardRarity == 4)
					{
						flag2 = true;
					}
				}
			}
			return cardData;
		}

		internal static void InitNewCard(CardRealtimeData newCard, ref Dictionary<CardType, List<string>> ____CardItemByType, ref Dictionary<CardType, List<string>> ____CardListByType, ref Dictionary<CardClass, List<string>> ____CardListByClass, ref List<string> ____CardListNotUpgraded, ref Dictionary<CardClass, List<string>> ____CardListNotUpgradedByClass, ref Dictionary<string, List<string>> ____CardListByClassType, ref Dictionary<string, int> ____CardEnergyCost)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Invalid comparison between Unknown and I4
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_00b0: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			newCard.UpdateId(newCard.Id);
			____CardEnergyCost.Add(newCard.Id, newCard.EnergyCost);
			Globals.Instance.IncludeInSearch(newCard.CardName, newCard.Id, true);
			____CardListByClass[newCard.CardClass].Add(newCard.Id);
			if ((int)newCard.CardUpgraded == 0)
			{
				____CardListNotUpgradedByClass[newCard.CardClass].Add(newCard.Id);
				____CardListNotUpgraded.Add(newCard.Id);
				if ((int)newCard.CardClass == 8)
				{
					if (!____CardItemByType.ContainsKey(newCard.CardType))
					{
						____CardItemByType.Add(newCard.CardType, new List<string>());
					}
					____CardItemByType[newCard.CardType].Add(newCard.Id);
				}
			}
			List<CardType> cardTypes = newCard.GetCardTypes();
			for (int i = 0; i < cardTypes.Count; i++)
			{
				if (!____CardListByType.ContainsKey(cardTypes[i]))
				{
					____CardListByType.Add(cardTypes[i], new List<string>());
				}
				____CardListByType[cardTypes[i]].Add(newCard.Id);
				string key = Enum.GetName(typeof(CardClass), newCard.CardClass) + "_" + Enum.GetName(typeof(CardType), cardTypes[i]);
				if (!____CardListByClassType.ContainsKey(key))
				{
					____CardListByClassType[key] = new List<string>();
				}
				____CardListByClassType[key].Add(newCard.Id);
				Globals.Instance.IncludeInSearch(Texts.Instance.GetText(Enum.GetName(typeof(CardType), cardTypes[i]), ""), newCard.Id, true);
			}
			newCard.PostInit();
			CardDescriptionExtension.SetDescriptionNew(newCard, true, (Character)null, true);
		}

		internal static void SetCardSourceField(CardDataNew source, string fieldName, object value)
		{
			Traverse.Create((object)source).Field(fieldName).SetValue(value);
		}

		public static CardRealtimeData AddNewCard(string id, string baseId, ref Dictionary<string, CardDataNew> ____CardsSource, ref Dictionary<string, CardRealtimeData> ____Cards, Action<CardDataNew> customize = null)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			id = id.ToLower();
			baseId = baseId.ToLower();
			if (!____CardsSource.TryGetValue(baseId, out var value))
			{
				Plugin.LogError("AddNewCard: source card '" + baseId + "' not found", "AddNewCard");
				return null;
			}
			CardDataNew val = Object.Instantiate<CardDataNew>(value);
			((Object)val).name = id;
			SetCardSourceField(val, "id", id);
			SetCardSourceField(val, "internalId", id);
			customize?.Invoke(val);
			CardRealtimeData val2 = new CardRealtimeData(val, id);
			____CardsSource[id] = val;
			____Cards[id] = val2;
			return val2;
		}
	}
	[HarmonyPatch]
	public class ChaoticCorruptionsPatches
	{
		public static bool devMode = Plugin.DevMode.Value;

		public static int i = 0;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Functions), "GetCardByRarity")]
		public static void GetCardByRarityPostfix(ref string __result, int rarity, CardRealtimeData _cardData, bool isChallenge = false)
		{
			Plugin.LogDebug("GetCardByRarityPostfix", "GetCardByRarityPostfix");
			if (Plugin.GuaranteeCorruptCards.Value || devMode || Random.Range(0, 100) <= Plugin.IncreaseCardCorruptionOdds.Value)
			{
				object obj;
				if (_cardData == null)
				{
					obj = null;
				}
				else
				{
					CardDataNew upgradesToRare = _cardData.UpgradesToRare;
					obj = ((upgradesToRare != null) ? upgradesToRare.Id : null);
				}
				if (obj == null)
				{
					obj = __result;
				}
				__result = (string)obj;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Loot), "GetLootItems")]
		public static void GetLootItemsPostfix(ref List<string> __result, string _itemListId, string _idAux = "")
		{
			Plugin.LogDebug("GetLootItemsPostfix", "GetLootItemsPostfix");
			if (!Plugin.GuaranteeCorruptItems.Value && Plugin.IncreaseItemCorruptionOdds.Value <= 0 && !devMode)
			{
				return;
			}
			for (int i = 0; i < __result.Count; i++)
			{
				CardRealtimeData cardData = Globals.Instance.GetCardData(__result[i], true);
				if (!(cardData == (CardRealtimeData)null) && (Plugin.GuaranteeCorruptItems.Value || (Plugin.IncreaseItemCorruptionOdds.Value > 0 && Random.Range(0, 100) <= Plugin.IncreaseItemCorruptionOdds.Value) || devMode))
				{
					List<string> obj = __result;
					int index = i;
					object obj2;
					if (cardData == null)
					{
						obj2 = null;
					}
					else
					{
						CardDataNew upgradesToRare = cardData.UpgradesToRare;
						obj2 = ((upgradesToRare != null) ? upgradesToRare.Id : null);
					}
					if (obj2 == null)
					{
						obj2 = __result[i];
					}
					obj[index] = (string)obj2;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Hero), "SetInitialItems")]
		public static void SetInitialItemsPrefix(ref Hero __instance, ref CardDataNew _cardData, ref int _rankLevel)
		{
			if (!(_cardData.Id == "harley") && (Plugin.CorruptStartingItems.Value || devMode))
			{
				Plugin.LogDebug("SetInitialItemsPrefix - corrupting " + _cardData.Id, "SetInitialItemsPrefix");
				CardDataNew obj = _cardData;
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					UpgradeData upgrade = obj.Upgrade;
					obj2 = ((upgrade != null) ? upgrade.UpgradesToRare : null);
				}
				if (obj2 == null)
				{
					obj2 = _cardData;
				}
				_cardData = (CardDataNew)obj2;
				_rankLevel = 0;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hero), "SetInitialCards")]
		public static void SetInitialCardsPostfix(ref Hero __instance, HeroData heroData)
		{
			Plugin.LogDebug("SetInitialCardsPostfix", "SetInitialCardsPostfix");
			try
			{
				List<string> cards = ((Character)__instance).Cards;
				if (Plugin.CompletelyRandomizeStartingDecks.Value || devMode)
				{
					Plugin.LogDebug("SetInitialCardsPostfix - randomizing " + ((Character)__instance).SourceName, "SetInitialCardsPostfix");
					for (int i = 0; i < cards.Count; i++)
					{
						string text = cards[i];
						Plugin.LogDebug(text, "SetInitialCardsPostfix");
						if (!Globals.Instance.GetCardData(text, true).HasFlag((CustomFlags)64) && !(Globals.Instance.GetCardData(text, true) == (CardRealtimeData)null))
						{
							Plugin.LogDebug("past check", "SetInitialCardsPostfix");
							string id = ChaoticCorruptionsFunctions.GetRandomCardWeighted(__instance, craftableOnly: false).Id;
							Plugin.LogDebug("newCard " + id, "SetInitialCardsPostfix");
							cards[i] = id;
						}
					}
					((Character)__instance).Cards = cards;
				}
				else if (Plugin.RandomizeStartingDecks.Value || devMode)
				{
					for (int j = 0; j < cards.Count; j++)
					{
						string text2 = cards[j];
						if (!Globals.Instance.GetCardData(text2, true).HasFlag((CustomFlags)64) && !(Globals.Instance.GetCardData(text2, true) == (CardRealtimeData)null))
						{
							cards[j] = ChaoticCorruptionsFunctions.GetRandomCardWeighted(__instance).Id;
						}
					}
					((Character)__instance).Cards = cards;
				}
				if (Plugin.CorruptStartingDecks.Value || devMode)
				{
					Plugin.LogDebug("SetInitialCardsPostfix - corrupting " + ((Character)__instance).SourceName, "SetInitialCardsPostfix");
					for (int k = 0; k < cards.Count; k++)
					{
						string text3 = cards[k];
						int index = k;
						Globals instance = Globals.Instance;
						object obj;
						if (instance == null)
						{
							obj = null;
						}
						else
						{
							CardRealtimeData cardData = instance.GetCardData(text3, true);
							if (cardData == null)
							{
								obj = null;
							}
							else
							{
								CardDataNew upgradesToRare = cardData.UpgradesToRare;
								obj = ((upgradesToRare != null) ? upgradesToRare.Id : null);
							}
						}
						if (obj == null)
						{
							obj = cards[k];
						}
						cards[index] = (string)obj;
					}
					((Character)__instance).Cards = cards;
				}
				if (Plugin.PandorasBox.Value || devMode)
				{
					Plugin.LogDebug("SetInitialCardsPostfix - Pandoras Box", "SetInitialCardsPostfix");
					for (int l = 0; l < cards.Count; l++)
					{
						string msg = cards[l];
						Plugin.LogDebug(msg, "SetInitialCardsPostfix");
						Plugin.LogDebug("past check", "SetInitialCardsPostfix");
						string text4 = (Plugin.CorruptStartingDecks.Value ? "chaoticchaosrare" : "chaoticchaos");
						Plugin.LogDebug("newCard " + text4, "SetInitialCardsPostfix");
						cards[l] = text4;
					}
					((Character)__instance).Cards = cards;
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError("Error: " + ex.Message, "SetInitialCardsPostfix");
				Plugin.LogError("Stack trace: " + ex.StackTrace, "SetInitialCardsPostfix");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Hero), "SetInitialCardsSingularity")]
		public static void SetSingularityInitialCardsPostfix(ref Hero __instance, HeroData heroData)
		{
			Plugin.LogDebug("SetInitialCardsSingularity", "SetSingularityInitialCardsPostfix");
			try
			{
				Random.InitState(Functions.GetDeterministicHashCode(AtOManager.Instance.GetGameId() + ((Character)__instance).SourceName + "com.binbin.ChaoticCorruptions"));
				List<string> cards = ((Character)__instance).Cards;
				if (Plugin.CompletelyRandomizeStartingDecks.Value || devMode)
				{
					Plugin.LogDebug("SetInitialCardsPostfix - randomizing " + ((Character)__instance).SourceName, "SetSingularityInitialCardsPostfix");
					for (int i = 0; i < cards.Count; i++)
					{
						string text = cards[i];
						Plugin.LogDebug(text, "SetSingularityInitialCardsPostfix");
						if (!Globals.Instance.GetCardData(text, true).HasFlag((CustomFlags)64) && !(Globals.Instance.GetCardData(text, true) == (CardRealtimeData)null))
						{
							Plugin.LogDebug("past check", "SetSingularityInitialCardsPostfix");
							string id = ChaoticCorruptionsFunctions.GetRandomCardWeighted(__instance, craftableOnly: false).Id;
							Plugin.LogDebug("newCard " + id, "SetSingularityInitialCardsPostfix");
							cards[i] = id;
						}
					}
					((Character)__instance).Cards = cards;
				}
				else if (Plugin.RandomizeStartingDecks.Value || devMode)
				{
					for (int j = 0; j < cards.Count; j++)
					{
						string text2 = cards[j];
						cards[j] = ChaoticCorruptionsFunctions.GetRandomCardWeighted(__instance).Id;
					}
					((Character)__instance).Cards = cards;
				}
				if (!Plugin.CorruptStartingDecks.Value && !devMode)
				{
					return;
				}
				Plugin.LogDebug("SetInitialCardsPostfix - corrupting " + ((Character)__instance).SourceName, "SetSingularityInitialCardsPostfix");
				for (int k = 0; k < cards.Count; k++)
				{
					string text3 = cards[k];
					int index = k;
					Globals instance = Globals.Instance;
					object obj;
					if (instance == null)
					{
						obj = null;
					}
					else
					{
						CardRealtimeData cardData = instance.GetCardData(text3, true);
						if (cardData == null)
						{
							obj = null;
						}
						else
						{
							CardDataNew upgradesToRare = cardData.UpgradesToRare;
							obj = ((upgradesToRare != null) ? upgradesToRare.Id : null);
						}
					}
					if (obj == null)
					{
						obj = cards[k];
					}
					cards[index] = (string)obj;
				}
				((Character)__instance).Cards = cards;
			}
			catch (Exception ex)
			{
				Plugin.LogError("Error: " + ex.Message, "SetSingularityInitialCardsPostfix");
				Plugin.LogError("Stack trace: " + ex.StackTrace, "SetSingularityInitialCardsPostfix");
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(CardCraftManager), "CanCraftThisCard")]
		public static bool CanCraftThisCard(CardCraftManager instance, CardRealtimeData cData)
		{
			throw new NotImplementedException("Reverse patch stub for CardCraftManager.CanCraftThisCard");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CardCraftManager), "CanCraftThisCard")]
		public static void CanCraftThisCardPostfix(ref CardCraftManager __instance, ref bool __result, CardRealtimeData cData)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Invalid comparison between Unknown and I4
			bool flag = CanCraftThisCard(__instance, Functions.GetCardDataFromCardData(cData, ""));
			if ((Plugin.CraftableCorruptions.Value || devMode) && (int)cData.CardUpgraded == 3 && flag)
			{
				__result = true;
			}
			else if (Plugin.OnlyCraftCorrupts.Value || devMode)
			{
				if ((int)cData.CardUpgraded == 3 && flag)
				{
					__result = true;
				}
				else
				{
					__result = false;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CardCraftManager), "ShowCardCraft")]
		public static void ShowCardCraftPostfix(CardCraftManager __instance, BotonAdvancedCraft ___buttonAdvancedCraft, int type = 0)
		{
			Plugin.LogDebug("ShowCardCraftPostfix", "ShowCardCraftPostfix");
			if ((Plugin.OnlyCraftCorrupts.Value || devMode) && __instance.craftType == 2)
			{
				Plugin.LogDebug("ShowCardCraftPostfix - setting Active", "ShowCardCraftPostfix");
				__instance.AdvancedCraft(true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "GetCraftCost")]
		public static void GetCraftCostPostfix(ref int __result, string cardId, float discountCraft = 0f, float discountUpgrade = 0f, int zoneTier = 0)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			Plugin.LogDebug("GetCraftCostPostfix - " + cardId, "GetCraftCostPostfix");
			if (Plugin.CraftableCorruptionsCost.Value > 0 && Plugin.CraftableCorruptions.Value)
			{
				CardRealtimeData cardData = Globals.Instance.GetCardData(cardId, true);
				if (!(cardData == (CardRealtimeData)null) && (int)cardData.CardUpgraded == 3)
				{
					int value = Plugin.CraftableCorruptionsCost.Value;
					value -= Functions.FuncRoundToInt((float)value * discountUpgrade);
					value += Functions.FuncRoundToInt((float)(value * SandboxManager.Instance.CardCraftPrice) * 0.01f);
					__result += value;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "CreateGameContentRoutine")]
		public static void CreateGameContent(ref IEnumerator __result, Globals __instance)
		{
			__result = Plugin.RunAfter(__result, CreateGameContentPostfix);
		}

		public static void CreateGameContentPostfix()
		{
			try
			{
				Plugin.LogDebug("starting", "CreateGameContentPostfix");
				Traverse val = Traverse.Create((object)Globals.Instance);
				Dictionary<string, CardDataNew> ____CardsSource = val.Field("_CardsSource").GetValue<Dictionary<string, CardDataNew>>();
				Dictionary<string, CardRealtimeData> ____Cards = val.Field("_Cards").GetValue<Dictionary<string, CardRealtimeData>>();
				Dictionary<CardType, List<string>> ____CardItemByType = val.Field("_CardItemByType").GetValue<Dictionary<CardType, List<string>>>();
				Dictionary<CardType, List<string>> ____CardListByType = val.Field("_CardListByType").GetValue<Dictionary<CardType, List<string>>>();
				Dictionary<CardClass, List<string>> ____CardListByClass = val.Field("_CardListByClass").GetValue<Dictionary<CardClass, List<string>>>();
				List<string> ____CardListNotUpgraded = val.Field("_CardListNotUpgraded").GetValue<List<string>>();
				Dictionary<CardClass, List<string>> ____CardListNotUpgradedByClass = val.Field("_CardListNotUpgradedByClass").GetValue<Dictionary<CardClass, List<string>>>();
				Dictionary<string, List<string>> ____CardListByClassType = val.Field("_CardListByClassType").GetValue<Dictionary<string, List<string>>>();
				Dictionary<string, int> ____CardEnergyCost = val.Field("_CardEnergyCost").GetValue<Dictionary<string, int>>();
				string text = "chaos";
				string text2 = "lasthope";
				CardRealtimeData cardData = Globals.Instance.GetCardData(text2, false);
				if (cardData == (CardRealtimeData)null)
				{
					Plugin.LogError("CreateGameContent: missing source card " + text2, "CreateGameContentPostfix");
					return;
				}
				CardRealtimeData val2 = ChaoticCorruptionsFunctions.AddNewCard("chaotic" + text, text2, ref ____CardsSource, ref ____Cards, delegate(CardDataNew src)
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					UpgradeData upgrade = src.Upgrade;
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "upgrade", (object)new UpgradeData(upgrade.UpgradesTo1, upgrade.UpgradesTo2, (CardUpgraded)3, "chaoticchaos", upgrade.UpgradesToRare));
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardClass", (object)(CardClass)9);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "energyCost", 0);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardType", (object)(CardType)0);
					src.CardManagement.AddCard = 1;
					src.CardManagement.AddCardChoose = 6;
					src.CardManagement.AddCardVanish = false;
					src.CardManagement.AddCardReducedCost = 1;
					src.CardManagement.AddCardCostTurn = false;
					src.CardManagement.AddCardPlace = (CardPlace)5;
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardName", "Chaos");
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardRarity", (object)(CardRarity)3);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "playable", true);
				});
				string text3 = "chaosrare";
				CardRealtimeData val3 = ChaoticCorruptionsFunctions.AddNewCard("chaotic" + text3, text2, ref ____CardsSource, ref ____Cards, delegate(CardDataNew src)
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					UpgradeData upgrade = src.Upgrade;
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "upgrade", (object)new UpgradeData(upgrade.UpgradesTo1, upgrade.UpgradesTo2, (CardUpgraded)3, "chaoticchaosrare", upgrade.UpgradesToRare));
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardClass", (object)(CardClass)9);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "energyCost", 0);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardType", (object)(CardType)0);
					src.CardManagement.AddCard = 1;
					src.Description.RelatedCards = new List<string>();
					src.CardManagement.AddCardChoose = 10;
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardName", "CHAOS!");
					src.CardManagement.AddCardVanish = false;
					src.CardManagement.AddCardReducedCost = 2;
					src.CardManagement.AddCardCostTurn = false;
					src.CardManagement.AddCardPlace = (CardPlace)5;
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "cardRarity", (object)(CardRarity)4);
					ChaoticCorruptionsFunctions.SetCardSourceField(src, "playable", true);
				});
				if (val2 != (CardRealtimeData)null)
				{
					ChaoticCorruptionsFunctions.InitNewCard(val2, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				}
				if (val3 != (CardRealtimeData)null)
				{
					ChaoticCorruptionsFunctions.InitNewCard(val3, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				}
				Traverse.Create((object)Globals.Instance).Field("_CardsSource").SetValue((object)____CardsSource);
				Traverse.Create((object)Globals.Instance).Field("_Cards").SetValue((object)____Cards);
				Traverse.Create((object)Globals.Instance).Field("_CardItemByType").SetValue((object)____CardItemByType);
				Traverse.Create((object)Globals.Instance).Field("_CardListByType").SetValue((object)____CardListByType);
				Traverse.Create((object)Globals.Instance).Field("_CardListByClass").SetValue((object)____CardListByClass);
				Traverse.Create((object)Globals.Instance).Field("_CardListNotUpgraded").SetValue((object)____CardListNotUpgraded);
				Traverse.Create((object)Globals.Instance).Field("_CardListNotUpgradedByClass").SetValue((object)____CardListNotUpgradedByClass);
				Traverse.Create((object)Globals.Instance).Field("_CardListByClassType").SetValue((object)____CardListByClassType);
				Traverse.Create((object)Globals.Instance).Field("_CardEnergyCost").SetValue((object)____CardEnergyCost);
				Plugin.LogDebug("CreateGameContentPostfix - done", "CreateGameContentPostfix");
			}
			catch (Exception ex)
			{
				Plugin.LogError("error: " + ex.Message, "CreateGameContentPostfix");
				Plugin.LogError("stack trace: " + ex.StackTrace, "CreateGameContentPostfix");
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CardCraftManager), "CreateDeck")]
		public static void CreateDeckPrefix(CardCraftManager __instance, Hero hero, bool fast = false)
		{
			Plugin.LogDebug(((Character)hero).SourceName + " cardsL=: " + string.Join(", ", ((Character)hero).Cards), "CreateDeckPrefix");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CardCraftManager), "CreateDeck")]
		public static void SetBlocked(CardCraftManager __instance)
		{
			Plugin.LogDebug("SetBlocked", "SetBlocked");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CardCraftManager), "RedrawGridLayout")]
		public static void RedrawGridLayout(CardCraftManager __instance)
		{
			Plugin.LogDebug("RedrawGridLayout", "RedrawGridLayout");
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CardVertical), "SetCard")]
		public static void SetCardPrefix(CardVertical __instance, string _cardId, int _cardType = 0, Hero _hero = null)
		{
			Plugin.LogDebug("SetCardPrefix - " + _cardId + " ", "SetCardPrefix");
			CardRealtimeData cardData = Globals.Instance.GetCardData(_cardId.Split('_')[0], false);
			Plugin.LogDebug(_cardId + " carddata " + cardData.Id + " ", "SetCardPrefix");
		}
	}
	[BepInPlugin("com.binbin.ChaoticCorruptions", "ChaoticCorruptions", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static string PluginName;

		public static string PluginVersion;

		public static string PluginGUID;

		internal static int ModDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

		private readonly Harmony harmony = new Harmony("com.binbin.ChaoticCorruptions");

		internal static ManualLogSource Log;

		public static string debugBase = "com.binbin.ChaoticCorruptions ";

		public static ConfigEntry<bool> EnableMod { get; set; }

		public static ConfigEntry<bool> EnableDebugging { get; set; }

		public static ConfigEntry<int> IncreaseCardCorruptionOdds { get; set; }

		public static ConfigEntry<int> IncreaseItemCorruptionOdds { get; set; }

		public static ConfigEntry<bool> GuaranteeCorruptCards { get; set; }

		public static ConfigEntry<bool> GuaranteeCorruptItems { get; set; }

		public static ConfigEntry<bool> CorruptStartingDecks { get; set; }

		public static ConfigEntry<bool> CorruptStartingItems { get; set; }

		public static ConfigEntry<bool> RandomizeStartingDecks { get; set; }

		public static ConfigEntry<bool> CompletelyRandomizeStartingDecks { get; set; }

		public static ConfigEntry<bool> PandorasBox { get; set; }

		public static ConfigEntry<bool> CraftableCorruptions { get; set; }

		public static ConfigEntry<int> CraftableCorruptionsCost { get; set; }

		public static ConfigEntry<bool> PurchaseableCorruptPets { get; set; }

		public static ConfigEntry<int> PurchaseableCorruptPetsMultiplier { get; set; }

		public static ConfigEntry<bool> OnlyCraftCorrupts { get; set; }

		public static ConfigEntry<bool> DevMode { get; set; }

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0039: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0066: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0093: Expected O, but got Unknown
			//IL_00a5: 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_00c0: Expected O, but got Unknown
			//IL_00c0: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_00ed: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_011a: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_0147: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_0174: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Expected O, but got Unknown
			//IL_01a1: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_01ce: Expected O, but got Unknown
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_01fb: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Expected O, but got Unknown
			//IL_0228: Expected O, but got Unknown
			//IL_023a: 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_0259: Expected O, but got Unknown
			//IL_0259: Expected O, but got Unknown
			//IL_026b: 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_0286: Expected O, but got Unknown
			//IL_0286: Expected O, but got Unknown
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Expected O, but got Unknown
			//IL_02b3: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string text = "ChaoticCorruptions";
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableMod"), true, new ConfigDescription("Enables the mod. If false, the mod will not work then next time you load the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableDebugging = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableDebugging"), false, new ConfigDescription("Enables the debugging", (AcceptableValueBase)null, Array.Empty<object>()));
			IncreaseCardCorruptionOdds = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "IncreaseCardCorruptionOdds"), 0, new ConfigDescription("Adds a second roll to corrupt cards. 100 will make it guaranteed", (AcceptableValueBase)null, Array.Empty<object>()));
			IncreaseItemCorruptionOdds = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "IncreaseItemCorruptionOdds"), 0, new ConfigDescription("Adds a second roll to corrupt items. 100 will make it guaranteed", (AcceptableValueBase)null, Array.Empty<object>()));
			GuaranteeCorruptCards = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "GuaranteeCorruptCards"), false, new ConfigDescription("Guarantees all card rewards are corrupted.", (AcceptableValueBase)null, Array.Empty<object>()));
			GuaranteeCorruptItems = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "GuaranteeCorruptItems"), false, new ConfigDescription("Guarantees all item rewardss are corrupted.", (AcceptableValueBase)null, Array.Empty<object>()));
			CorruptStartingDecks = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "CorruptStartingDecks"), false, new ConfigDescription("Forces all starting cards to be corrupted.", (AcceptableValueBase)null, Array.Empty<object>()));
			CorruptStartingItems = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "CorruptStartingItems"), false, new ConfigDescription("Forces all starting items to be corrupted.", (AcceptableValueBase)null, Array.Empty<object>()));
			RandomizeStartingDecks = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "RandomizeStartingDecks"), true, new ConfigDescription("Randomizes starting decks from all craftable cards. If CorruptStartingDecks is active, they are all corrupted", (AcceptableValueBase)null, Array.Empty<object>()));
			CompletelyRandomizeStartingDecks = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "CompletelyRandomizeStartingDecks"), true, new ConfigDescription("Randomizes starting decks from all available cards for each hero's class. If CorruptStartingDecks is active, they are all corrupted", (AcceptableValueBase)null, Array.Empty<object>()));
			PandorasBox = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "PandorasBox"), false, new ConfigDescription("If true, replaces your starting deck with Chaos (discovers a card). If CorruptStartingDecks is active, replaces your deck with CHAOS (discovers a corrupted card). Overrides all other starting deck options.", (AcceptableValueBase)null, Array.Empty<object>()));
			CraftableCorruptions = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "CraftableCorruptions"), true, new ConfigDescription("Makes corrupted cards craftable", (AcceptableValueBase)null, Array.Empty<object>()));
			CraftableCorruptionsCost = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition(text, "CraftableCorruptionsCost"), 800, new ConfigDescription("The cost added to the regular crafting cost that will be added to the card to craft the corrupted version.", (AcceptableValueBase)null, Array.Empty<object>()));
			OnlyCraftCorrupts = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "OnlyCraftCorrupts"), false, new ConfigDescription("Makes it so that the only cards you can craft are corrupted cards", (AcceptableValueBase)null, Array.Empty<object>()));
			DevMode = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "DevMode"), false, new ConfigDescription("Enables all of the things for testing.", (AcceptableValueBase)null, Array.Empty<object>()));
			PluginName = "ChaoticCorruptions";
			PluginVersion = "1.1.1";
			PluginGUID = "com.binbin.ChaoticCorruptions";
			if (EnableMod.Value)
			{
				if (EssentialsCompatibility.Enabled)
				{
					EssentialsCompatibility.EssentialsRegister();
				}
				else
				{
					LogInfo(PluginGUID + " " + PluginVersion + " has loaded!");
				}
				harmony.PatchAll();
			}
		}

		internal static void LogDebug(string msg, [CallerMemberName] string caller = "")
		{
			if (EnableDebugging.Value)
			{
				Log.LogDebug((object)(debugBase + "- " + caller + " - " + msg));
			}
		}

		internal static void LogInfo(string msg)
		{
			Log.LogInfo((object)(debugBase + msg));
		}

		internal static void LogError(string msg, [CallerMemberName] string caller = "")
		{
			Log.LogError((object)(debugBase + "- " + caller + " - " + msg));
		}

		public static IEnumerator RunAfter(IEnumerator original, Action action)
		{
			while (original.MoveNext())
			{
				yield return original.Current;
			}
			action();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.binbin.ChaoticCorruptions";

		public const string PLUGIN_NAME = "ChaoticCorruptions";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}