Decompiled source of AtOEndless v1.3.2

BepInEx/plugins/com.corgan.AtOEndless.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.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.UIElements.Collections;

[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 = "")]
[assembly: AssemblyCompany("com.corgan.AtOEndless")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3ef9993c2ddc360b2de0c60694293cfb4da4089d")]
[assembly: AssemblyProduct("AtOEndless")]
[assembly: AssemblyTitle("com.corgan.AtOEndless")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 AtOEndless
{
	[Serializable]
	public class AtOEndlessSaveData
	{
		private HashSet<string> activeBlessings = new HashSet<string>();

		public void FillData()
		{
			Plugin.LogInfo("SET ACTIVE BLESSINGS: " + string.Join(", ", AtOEndless.activeBlessings));
			activeBlessings = AtOEndless.activeBlessings;
		}

		public void LoadData()
		{
			AtOEndless.activeBlessings = activeBlessings;
			Plugin.LogInfo("GET ACTIVE BLESSINGS: " + string.Join(", ", activeBlessings));
		}
	}
	[HarmonyPatch]
	public class AtOEndless
	{
		public static HashSet<string> activeBlessings = new HashSet<string>();

		public static List<string> availableBlessings = new List<string>();

		public static CardType blessingCardType = (CardType)(Enum.GetValues(typeof(CardType)).Cast<CardType>().Max() + 1);

		public static EventActivation blessingCombatStart = (EventActivation)(Enum.GetValues(typeof(EventActivation)).Cast<EventActivation>().Max() + 1);

		public static EventActivation blessingBeginRound = (EventActivation)(Enum.GetValues(typeof(EventActivation)).Cast<EventActivation>().Max() + 2);

		public static bool refreshed = false;

		public static Dictionary<Zone, string> portalStrings = new Dictionary<Zone, string>
		{
			{
				(Zone)0,
				"grassy"
			},
			{
				(Zone)3,
				"icy"
			},
			{
				(Zone)2,
				"swampy"
			},
			{
				(Zone)1,
				"molten"
			},
			{
				(Zone)12,
				"sandy"
			},
			{
				(Zone)14,
				"salty"
			},
			{
				(Zone)4,
				"cosmic"
			}
		};

		public static List<string> blessingCards = new List<string>(33)
		{
			"armageddon", "bloodpuddle", "chaospuddle", "chaoticwind", "coldfront", "colorfulpuddle", "darkpuddle", "deathgrip", "electricpuddle", "empower",
			"firecrackers", "heavenlyarmaments", "hexproof", "holypuddle", "icypuddle", "ironclad", "lanternfestival", "lavabursts", "lavapuddle", "livingforest",
			"lonelyblob", "metalpuddle", "poisonfields", "putrefaction", "rosegarden", "sacredground", "subzero", "thegrinch", "thunderstorm", "toxicpuddle",
			"upwind", "vigorous", "waterpuddle"
		};

		public static Dictionary<Zone, List<string>> RemoveRequirementsByZone = new Dictionary<Zone, List<string>>
		{
			{
				(Zone)0,
				new List<string>(1) { "treasurehuntii" }
			},
			{
				(Zone)3,
				new List<string>(1) { "darkdeal" }
			},
			{
				(Zone)1,
				new List<string>(5) { "armblowtorch", "armchargedrod", "armcoolingengine", "armdisclauncher", "armsmallcannon" }
			},
			{
				(Zone)2,
				new List<string>()
			},
			{
				(Zone)12,
				new List<string>(3) { "ulmininportal", "ulminindown", "riftulmi61" }
			},
			{
				(Zone)14,
				new List<string>(6) { "sahtidown", "sahtipolizonevent", "sahtiship", "dreadroom", "dreadup", "dreadmastcannon" }
			},
			{
				(Zone)4,
				new List<string>()
			}
		};

		public static Dictionary<Zone, List<string>> AddRequirementsByZone = new Dictionary<Zone, List<string>>
		{
			{
				(Zone)0,
				new List<string>(6) { "crossroadnorth", "crossroadsouth", "caravannopay", "fungamemill", "riftsen47", "riftsen48" }
			},
			{
				(Zone)3,
				new List<string>(3) { "boatfaenlor", "riftfaen42", "riftfaen43" }
			},
			{
				(Zone)1,
				new List<string>(4) { "lavacascade", "goblinnorth", "riftvelka39", "riftvelka40" }
			},
			{
				(Zone)2,
				new List<string>(5) { "boatup", "boatcenter", "boatdown", "riftaqua46", "riftaqua47" }
			},
			{
				(Zone)12,
				new List<string>(3) { "ulmininup", "riftulmi60", "riftulmi61" }
			},
			{
				(Zone)14,
				new List<string>(6) { "sahtiup", "dreaddown", "sahtipirateking", "sahtipolizon", "riftsahti67", "riftsahti68" }
			},
			{
				(Zone)4,
				new List<string>(4) { "voidnorth", "voidnorthpass", "voidsouth", "voidsouthpass" }
			}
		};

		public static string[] zoneStartNodes = new string[7] { "sen_0", "faen_0", "aqua_0", "velka_0", "ulmin_0", "sahti_0", "voidlow_0" };

		public static CardData GetRandomBlessing(List<string> ignore = null)
		{
			List<string> list = availableBlessings.ToList();
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = Globals.Instance.GetCardData(activeBlessing, false);
				cardData = Functions.GetCardDataFromCardData(cardData, "");
				if ((Object)(object)cardData != (Object)null && list.Contains(cardData.Id))
				{
					Plugin.LogInfo("Active Blessing: " + cardData.Id);
					list.Remove(cardData.Id);
				}
			}
			if (ignore != null)
			{
				foreach (string item in ignore)
				{
					CardData cardData2 = Globals.Instance.GetCardData(item, false);
					cardData2 = Functions.GetCardDataFromCardData(cardData2, "");
					if ((Object)(object)cardData2 != (Object)null && list.Contains(cardData2.Id))
					{
						Plugin.LogInfo("Ignore Blessing: " + cardData2.Id);
						list.Remove(cardData2.Id);
					}
				}
			}
			Plugin.LogInfo($"Blessing Cards: {list.Count}");
			if (list.Count > 0)
			{
				int num = Random.Range(0, list.Count);
				string text = list[num];
				Plugin.LogInfo($"Random Corruption Index: {num} - {text}");
				CardData val = Globals.Instance.GetCardData(text, false);
				if (AtOManager.Instance.GetTownTier() == 0)
				{
					val = Functions.GetCardDataFromCardData(val, "");
					if ((Object)(object)val != (Object)null)
					{
						text = val.Id;
					}
				}
				if (AtOManager.Instance.GetTownTier() >= 1)
				{
					val = Functions.GetCardDataFromCardData(val, "A");
					if ((Object)(object)val != (Object)null)
					{
						text = val.Id;
					}
				}
				if (AtOManager.Instance.GetTownTier() >= 2)
				{
					val = Functions.GetCardDataFromCardData(val, "B");
					if ((Object)(object)val != (Object)null)
					{
						text = val.Id;
					}
				}
				if (AtOManager.Instance.GetTownTier() >= 3)
				{
					val = Functions.GetCardDataFromCardData(val, "RARE");
					if ((Object)(object)val != (Object)null)
					{
						text = val.Id;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					val = Globals.Instance.GetCardData(text, false);
				}
				Plugin.LogInfo("Got Corruption Card: " + val.Id);
				return val;
			}
			return null;
		}

		public static void BeginMatchBlessings()
		{
			Plugin.LogInfo("BEGIN MATCH BLESSINGS " + string.Join(", ", activeBlessings));
			Hero[] value = Traverse.Create((object)MatchManager.Instance).Field("TeamHero").GetValue<Hero[]>();
			Plugin.LogInfo($"Got Heroes: {value.Length}");
			NPC[] value2 = Traverse.Create((object)MatchManager.Instance).Field("TeamNPC").GetValue<NPC[]>();
			Plugin.LogInfo($"Got NPCs: {value2.Length}");
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = MatchManager.Instance.GetCardData(activeBlessing, true);
				Plugin.LogInfo("Got Blessing Data for " + cardData.Id);
			}
		}

		public static void CombatStartBlessings()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LogInfo("COMBAT START BLESSINGS " + string.Join(", ", activeBlessings));
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = MatchManager.Instance.GetCardData(activeBlessing, true);
				if (!((Object)(object)cardData.Item != (Object)null) || cardData.Item.Activation != blessingCombatStart)
				{
					continue;
				}
				cardData.EnergyCost = 0;
				cardData.Vanish = true;
				cardData.CardClass = (CardClass)7;
				MatchManager.Instance.GenerateNewCard(1, activeBlessing, false, (CardPlace)4, (CardData)null, (CardData)null, -1, true, 0);
				Hero[] value = Traverse.Create((object)MatchManager.Instance).Field("TeamHero").GetValue<Hero[]>();
				for (int i = 0; i < 4; i++)
				{
					if (value[i] != null && ((Character)value[i]).Alive)
					{
						((Character)value[i]).DoItem(blessingCombatStart, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
						break;
					}
				}
			}
		}

		public static void BeginRoundBlessings()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Invalid comparison between Unknown and I4
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Invalid comparison between Unknown and I4
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Invalid comparison between Unknown and I4
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Invalid comparison between Unknown and I4
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Invalid comparison between Unknown and I4
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Invalid comparison between Unknown and I4
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Invalid comparison between Unknown and I4
			//IL_0289: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LogInfo("BEGIN ROUND BLESSINGS " + string.Join(", ", activeBlessings));
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = MatchManager.Instance.GetCardData(activeBlessing, true);
				if (!((Object)(object)cardData.Item != (Object)null) || cardData.Item.Activation != blessingBeginRound)
				{
					continue;
				}
				Hero[] value = Traverse.Create((object)MatchManager.Instance).Field("TeamHero").GetValue<Hero[]>();
				NPC[] value2 = Traverse.Create((object)MatchManager.Instance).Field("TeamNPC").GetValue<NPC[]>();
				Plugin.LogInfo($"{activeBlessing} - BEGIN ROUND - {cardData.Item.ItemTarget}");
				if ((int)cardData.Item.ItemTarget == 3)
				{
					for (int i = 0; i < 4; i++)
					{
						if (value[i] != null && ((Character)value[i]).Alive)
						{
							((Character)value[i]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							break;
						}
					}
				}
				else if ((int)cardData.Item.ItemTarget == 1 || (int)cardData.Item.ItemTarget == 0)
				{
					if ((int)cardData.Item.ItemTarget == 0)
					{
						for (int j = 0; j < 4; j++)
						{
							if (value[j] != null && ((Character)value[j]).Alive)
							{
								((Character)value[j]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							}
						}
						continue;
					}
					bool flag = false;
					while (!flag)
					{
						int randomIntRange = MatchManager.Instance.GetRandomIntRange(0, 4, "default", "");
						if (value[randomIntRange] != null && ((Character)value[randomIntRange]).Alive)
						{
							((Character)value[randomIntRange]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							flag = true;
						}
					}
				}
				else if ((int)cardData.Item.ItemTarget == 4)
				{
					for (int k = 0; k < 4; k++)
					{
						if (value2[k] != null && ((Character)value2[k]).Alive)
						{
							((Character)value2[k]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							break;
						}
					}
				}
				else
				{
					if ((int)cardData.Item.ItemTarget != 2 && (int)cardData.Item.ItemTarget != 6)
					{
						continue;
					}
					if ((int)cardData.Item.ItemTarget == 6)
					{
						for (int l = 0; l < 4; l++)
						{
							if (value2[l] != null && ((Character)value2[l]).Alive)
							{
								((Character)value2[l]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							}
						}
						continue;
					}
					bool flag2 = false;
					while (!flag2)
					{
						int randomIntRange2 = MatchManager.Instance.GetRandomIntRange(0, 4, "default", "");
						if (value2[randomIntRange2] != null && ((Character)value2[randomIntRange2]).Alive)
						{
							((Character)value2[randomIntRange2]).DoItem(blessingBeginRound, cardData, cardData.Item.Id, (Character)null, 0, "", 0, (CardData)null);
							flag2 = true;
						}
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Enum), "GetName")]
		public static void GetName(Type enumType, object value, ref string __result)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (enumType == typeof(CardType) && (CardType)value == blessingCardType)
			{
				__result = "Blessing";
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ItemCombatIcon), "DoHover")]
		public static void DoHover(ItemCombatIcon __instance, bool state, ref CardData ___cardData)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)___cardData == (Object)null) && ___cardData.CardType == blessingCardType)
			{
				((Component)__instance.spriteBackgroundHover).gameObject.SetActive(true);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "ActivateItem")]
		public static void ActivateItem(ref Character __instance, EventActivation theEvent, Character target, int auxInt, string auxString, ref bool ___isHero, ref Item ___itemClass, ref CardData ___cardCasted)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Invalid comparison between Unknown and I4
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MatchManager.Instance == (Object)null)
			{
				return;
			}
			int num = -1;
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = MatchManager.Instance.GetCardData(activeBlessing, true);
				if (!((Object)(object)cardData != (Object)null))
				{
					continue;
				}
				ItemData val = null;
				if ((Object)(object)cardData.Item != (Object)null)
				{
					val = cardData.Item;
				}
				else if ((Object)(object)cardData.ItemEnchantment != (Object)null)
				{
					val = cardData.ItemEnchantment;
				}
				if (!((Object)(object)val != (Object)null) || (val.ActivationOnlyOnHeroes && ___isHero) || (val.Activation != theEvent && ((int)val.Activation != 20 || (int)theEvent != 29)))
				{
					continue;
				}
				if (Globals.Instance.ShowDebug)
				{
					Functions.DebugLogGD("[Character/ActivateItem] Checking if " + activeBlessing + " will activate", "item");
				}
				Plugin.LogInfo($"{theEvent} - {cardData.Id} - {__instance.HeroIndex} - {val.ItemTarget}");
				if (___itemClass.DoItem(theEvent, cardData, activeBlessing, __instance, target, auxInt, auxString, 0, ___cardCasted, true))
				{
					num++;
					if (Globals.Instance.ShowDebug)
					{
						Functions.DebugLogGD("[Character/ActivateItem] " + activeBlessing + "-> OK", "item");
					}
					MatchManager.Instance.DoItem(__instance, theEvent, cardData, activeBlessing, target, auxInt, auxString, num);
				}
				else if (Globals.Instance.ShowDebug)
				{
					Functions.DebugLogGD(activeBlessing + " -> XXXXXX", "item");
				}
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static IEnumerable<CodeInstruction> BeginMatch_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(MatchManager), "SetInitiatives", (Type[])null, (Type[])null), (string)null)
			}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AtOEndless), "BeginMatchBlessings", (Type[])null, (Type[])null))
			});
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static IEnumerable<CodeInstruction> NextTurnContinue_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, generator);
			val.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(MatchManager), "corruptionItem"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldnull, (object)null, (string)null)
			}).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
			{
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AtOEndless), "CombatStartBlessings", (Type[])null, (Type[])null))
			}).Advance(4)
				.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
				{
					new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(MatchManager), "corruptionItem"), (string)null),
					new CodeMatch((OpCode?)OpCodes.Ldnull, (object)null, (string)null)
				})
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AtOEndless), "BeginRoundBlessings", (Type[])null, (Type[])null))
				});
			return val.InstructionEnumeration();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Node), "OnMouseUp")]
		public static void OnMouseUp(ref Node __instance)
		{
			if (Functions.ClickedThisTransform(((Component)__instance).transform) && !AlertManager.Instance.IsActive() && !GameManager.Instance.IsTutorialActive() && !SettingsManager.Instance.IsActive() && !DamageMeterManager.Instance.IsActive() && (!Object.op_Implicit((Object)(object)MapManager.Instance) || !MapManager.Instance.IsCharacterUnlock()) && (!Object.op_Implicit((Object)(object)MapManager.Instance) || (!MapManager.Instance.IsCorruptionOver() && !MapManager.Instance.IsConflictOver())) && (!Object.op_Implicit((Object)(object)MapManager.Instance) || !MapManager.Instance.selectedNode) && !Object.op_Implicit((Object)(object)EventManager.Instance) && ((object)(SteamId)(ref SteamManager.Instance.steamId)).ToString() == "76561197965495526")
			{
				GameManager.Instance.SetCursorPlain();
				MapManager.Instance.HidePopup();
				MapManager.Instance.PlayerSelectedNode(__instance, false);
				GameManager.Instance.PlayAudio(AudioManager.Instance.soundButtonClick, 0f, 0f);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Functions), "DebugLogGD")]
		public static bool DebugLogGD(string str, string type)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (type != "")
			{
				stringBuilder.Append("[");
				stringBuilder.Append(type.ToUpper());
				stringBuilder.Append("] ");
			}
			stringBuilder.Append(str);
			Plugin.LogInfo(stringBuilder.ToString());
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(AtOManager), "BeginAdventure")]
		public static void BeginAdventure(ref AtOManager __instance)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge())
			{
				activeBlessings = new HashSet<string>();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MatchManager), "FinishLoadTurnData")]
		public static void FinishLoadTurnData(ref MatchManager __instance)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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)
			if (GameManager.Instance.IsObeliskChallenge() || GameManager.Instance.IsWeeklyChallenge())
			{
				return;
			}
			List<ItemCombatIcon> list = new List<ItemCombatIcon>();
			int num = 0;
			foreach (string activeBlessing in activeBlessings)
			{
				CardData cardData = Globals.Instance.GetCardData(activeBlessing, false);
				ItemCombatIcon val = Object.Instantiate<ItemCombatIcon>(__instance.iconCorruption, ((Component)__instance.iconCorruption).transform.parent);
				((Object)((Component)val).gameObject).name = "CorruptionIcon";
				float num2 = ((Component)val).transform.localPosition.x - 3f - 0.7f * (float)(num % 6);
				float num3 = ((Component)val).transform.localPosition.y - 0.7f * (float)Mathf.FloorToInt((float)(num / 6));
				((Component)val).transform.localPosition = new Vector3(num2, num3, ((Component)val).transform.localPosition.z + 3f);
				Plugin.LogInfo("GAME OBJECT " + ((Object)((Component)val).gameObject).name);
				list.Add(val);
				num++;
				if ((Object)(object)cardData != (Object)null)
				{
					((Component)((Component)val).transform).gameObject.SetActive(true);
					val.ShowIconCorruption(cardData);
					Plugin.LogInfo("CARD ID " + cardData.Id);
				}
				else
				{
					((Component)((Component)val).transform).gameObject.SetActive(false);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(CardData), "SetDescriptionNew")]
		public static void SetDescriptionNewPre(ref CardData __instance, bool forceDescription, Character character, bool includeInSearch, out EventActivation __state)
		{
			//IL_0007: 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_002f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected I4, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected I4, but got Unknown
			__state = (EventActivation)0;
			if (__instance.CardType == blessingCardType && (Object)(object)__instance.Item != (Object)null)
			{
				if (__instance.Item.Activation == blessingBeginRound)
				{
					__state = (EventActivation)(int)__instance.Item.Activation;
					__instance.Item.Activation = (EventActivation)2;
				}
				if (__instance.Item.Activation == blessingCombatStart)
				{
					__state = (EventActivation)(int)__instance.Item.Activation;
					__instance.Item.Activation = (EventActivation)1;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CardData), "SetDescriptionNew")]
		public static void SetDescriptionNewPost(ref CardData __instance, bool forceDescription, Character character, bool includeInSearch, EventActivation __state)
		{
			//IL_0003: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.CardType == blessingCardType && (Object)(object)__instance.Item != (Object)null && (int)__state > 0)
			{
				__instance.Item.Activation = __state;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SaveManager), "SaveGame")]
		public static void SaveGame(int slot, bool backUp)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			string value = Traverse.Create(typeof(SaveManager)).Field("saveGameExtensionBK").GetValue<string>();
			string value2 = Traverse.Create(typeof(SaveManager)).Field("saveGameExtension").GetValue<string>();
			byte[] value3 = Traverse.Create(typeof(SaveManager)).Field("key").GetValue<byte[]>();
			byte[] value4 = Traverse.Create(typeof(SaveManager)).Field("iv").GetValue<byte[]>();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(Application.persistentDataPath);
			stringBuilder.Append("/");
			stringBuilder.Append(SteamId.op_Implicit(SteamManager.Instance.steamId));
			stringBuilder.Append("/");
			stringBuilder.Append(GameManager.Instance.ProfileFolder);
			stringBuilder.Append("endless_");
			stringBuilder.Append(slot);
			StringBuilder stringBuilder2 = new StringBuilder();
			stringBuilder2.Append(stringBuilder.ToString());
			stringBuilder2.Append(value);
			stringBuilder.Append(value2);
			string text = stringBuilder.ToString();
			string destFileName = stringBuilder2.ToString();
			if (backUp && File.Exists(text))
			{
				File.Copy(text, destFileName, overwrite: true);
			}
			DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
			try
			{
				FileStream fileStream = new FileStream(text, FileMode.Create, FileAccess.Write);
				using (CryptoStream cryptoStream = new CryptoStream(fileStream, dESCryptoServiceProvider.CreateEncryptor(value3, value4), CryptoStreamMode.Write))
				{
					BinaryFormatter binaryFormatter = new BinaryFormatter();
					AtOEndlessSaveData atOEndlessSaveData = new AtOEndlessSaveData();
					atOEndlessSaveData.FillData();
					CryptoStream serializationStream = cryptoStream;
					binaryFormatter.Serialize(serializationStream, atOEndlessSaveData);
					cryptoStream.Close();
				}
				fileStream.Close();
			}
			catch
			{
				Plugin.LogInfo("Failed to save AtOEndless Data");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SaveManager), "LoadGame")]
		public static void LoadGame(int slot, bool comingFromReloadCombat)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			string value = Traverse.Create(typeof(SaveManager)).Field("saveGameExtension").GetValue<string>();
			byte[] value2 = Traverse.Create(typeof(SaveManager)).Field("key").GetValue<byte[]>();
			byte[] value3 = Traverse.Create(typeof(SaveManager)).Field("iv").GetValue<byte[]>();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(Application.persistentDataPath);
			stringBuilder.Append("/");
			stringBuilder.Append(SteamId.op_Implicit(SteamManager.Instance.steamId));
			stringBuilder.Append("/");
			stringBuilder.Append(GameManager.Instance.ProfileFolder);
			stringBuilder.Append("endless_");
			stringBuilder.Append(slot);
			stringBuilder.Append(value);
			string path = stringBuilder.ToString();
			if (!File.Exists(path))
			{
				Plugin.LogInfo("ERROR File does not exists");
				return;
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			if (fileStream.Length == 0)
			{
				fileStream.Close();
				return;
			}
			DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
			try
			{
				CryptoStream cryptoStream = new CryptoStream(fileStream, dESCryptoServiceProvider.CreateDecryptor(value2, value3), CryptoStreamMode.Read);
				(new BinaryFormatter().Deserialize(cryptoStream) as AtOEndlessSaveData).LoadData();
				cryptoStream.Close();
			}
			catch (SerializationException ex)
			{
				Plugin.LogInfo("Failed to deserialize LoadGame. Reason: " + ex.Message);
			}
			fileStream.Close();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SaveManager), "DeleteGame")]
		public static void DeleteGame(int slot, bool sendTelemetry)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			string value = Traverse.Create(typeof(SaveManager)).Field("saveGameExtension").GetValue<string>();
			string value2 = Traverse.Create(typeof(SaveManager)).Field("saveGameExtensionBK").GetValue<string>();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(Application.persistentDataPath);
			stringBuilder.Append("/");
			stringBuilder.Append(SteamId.op_Implicit(SteamManager.Instance.steamId));
			stringBuilder.Append("/");
			stringBuilder.Append(GameManager.Instance.ProfileFolder);
			stringBuilder.Append("endless_");
			stringBuilder.Append(slot);
			string path = stringBuilder.ToString() + value;
			string path2 = stringBuilder.ToString() + value2;
			if (File.Exists(path))
			{
				File.Delete(path);
			}
			if (File.Exists(path2))
			{
				File.Delete(path2);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Character), "LevelUp")]
		public static void LevelUp(Character __instance, HeroData ___heroData)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge() && AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), "") && ___heroData.HeroSubClass.MaxHp.Length < 9)
			{
				int[] array = new int[9];
				___heroData.HeroSubClass.MaxHp.CopyTo(array, 4);
				___heroData.HeroSubClass.MaxHp.CopyTo(array, 0);
				___heroData.HeroSubClass.MaxHp = array;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SubClassData), "GetTraitLevel")]
		public static void GetTraitLevel(SubClassData __instance, string traitName, ref int __result)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge() && AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), ""))
			{
				Hero[] team = AtOManager.Instance.GetTeam();
				Hero val = team.Where((Hero hero) => ((Character)hero).SubclassName.ToLower() == __instance.SubClassName.ToLower()).First();
				if (((Character)val).Traits.Length < 9)
				{
					string[] array = new string[9];
					((Character)val).Traits.CopyTo(array, 0);
					((Character)val).Traits = array;
				}
				if (((Character)val).Traits[__result] != null && ((Character)val).Traits[__result] != "" && ((Character)val).Traits[__result] != traitName)
				{
					__result += 4;
				}
				Plugin.LogInfo($"GetTraitLevel: {__result} - {((Character)val).Traits.Length} - {((Character)val).Traits[__result]}");
				string[] traits = ((Character)val).Traits;
				foreach (string text in traits)
				{
					Plugin.LogInfo("GetTraitLevel: " + text);
				}
			}
		}

		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(CharacterWindowUI), "GetTraitData")]
		public static TraitData GetTraitData(CharacterWindowUI __instance, int level, int index)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			return new TraitData();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CharacterWindowUI), "DrawLevelButtons")]
		public static void DrawLevelButtons(ref CharacterWindowUI __instance, int heroLevel, bool levelUp, ref Hero ___currentHero, ref SubClassData ___currentSCD)
		{
			if (GameManager.Instance.IsObeliskChallenge() || GameManager.Instance.IsWeeklyChallenge() || !AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), ""))
			{
				return;
			}
			string color = Globals.Instance.ClassColor[((Character)___currentHero).ClassName];
			int characterTier = PlayerManager.Instance.GetCharacterTier("", "trait", ((Character)___currentHero).PerkRank);
			for (int i = 1; i < 5; i++)
			{
				bool active = false;
				bool enable = false;
				int num = i * 2;
				int num2 = num + 1;
				TraitData traitData = GetTraitData(__instance, i, 0);
				if (((Character)___currentHero).HaveTrait(traitData.Id))
				{
					enable = true;
				}
				else if ((i == heroLevel || i + 4 == heroLevel) && levelUp && (((Character)___currentHero).Owner == null || ((Character)___currentHero).Owner == "" || ((Character)___currentHero).Owner == NetworkManager.Instance.GetPlayerNick()) && !((Character)___currentHero).HaveTrait(traitData.Id))
				{
					active = true;
				}
				__instance.traitLevel[num].SetHeroIndex(__instance.heroIndex);
				__instance.traitLevel[num].SetColor(color);
				__instance.traitLevel[num].SetPosition(1);
				__instance.traitLevel[num].SetEnable(enable);
				__instance.traitLevel[num].SetActive(active);
				__instance.traitLevel[num].SetTrait(traitData, characterTier);
				TraitData traitData2 = GetTraitData(__instance, i, 1);
				bool enable2 = false;
				bool active2 = false;
				if (((Character)___currentHero).HaveTrait(traitData2.Id))
				{
					enable2 = true;
				}
				else if ((i == heroLevel || i + 4 == heroLevel) && levelUp && (((Character)___currentHero).Owner == null || ((Character)___currentHero).Owner == "" || ((Character)___currentHero).Owner == NetworkManager.Instance.GetPlayerNick()) && !((Character)___currentHero).HaveTrait(traitData2.Id))
				{
					active2 = true;
				}
				__instance.traitLevel[num2].SetHeroIndex(__instance.heroIndex);
				__instance.traitLevel[num2].SetColor(color);
				__instance.traitLevel[num2].SetPosition(2);
				__instance.traitLevel[num2].SetEnable(enable2);
				__instance.traitLevel[num2].SetActive(active2);
				__instance.traitLevel[num2].SetTrait(traitData2, characterTier);
				StringBuilder stringBuilder = new StringBuilder();
				bool flag = false;
				if ((i < heroLevel || ((i == heroLevel || i + 4 == heroLevel) && levelUp)) && (((Character)___currentHero).Owner == null || ((Character)___currentHero).Owner == "" || ((Character)___currentHero).Owner == NetworkManager.Instance.GetPlayerNick()))
				{
					flag = true;
				}
				stringBuilder.Append("<size=+.4>");
				if (flag)
				{
					stringBuilder.Append("<color=#FC0>");
				}
				stringBuilder.Append(Texts.Instance.GetText("levelNumber", "").Replace("<N>", $"{i + 1}&{i + 5}"));
				if (flag)
				{
					stringBuilder.Append("</color>");
				}
				stringBuilder.Append("</size>");
				stringBuilder.Append("\n");
				if (flag)
				{
					stringBuilder.Append("<color=#EE5A3C>");
				}
				stringBuilder.Append(Texts.Instance.GetText("incrementMaxHp", "").Replace("<N>", ___currentSCD.MaxHp[i].ToString()));
				if (flag)
				{
					stringBuilder.Append("</color>");
				}
				__instance.traitLevelText[i].text = stringBuilder.ToString();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Node), "AssignNode")]
		public static void AssignNodePre(ref AtOManager __instance, out string[][] __state)
		{
			__state = new string[2][]
			{
				AtOManager.Instance.mapVisitedNodes.ToArray(),
				AtOManager.Instance.mapVisitedNodesAction.ToArray()
			};
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge())
			{
				AtOManager.Instance.mapVisitedNodes.Clear();
				AtOManager.Instance.mapVisitedNodesAction.Clear();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Node), "AssignNode")]
		public static void AssignNodePost(ref Node __instance, string[][] __state)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge())
			{
				List<string> mapVisitedNodes = AtOManager.Instance.mapVisitedNodes;
				string[] array = __state[0];
				int num = 0;
				string[] array2 = new string[array.Length];
				string[] array3 = array;
				foreach (string text in array3)
				{
					array2[num] = text;
					num++;
				}
				mapVisitedNodes.AddRange(new <>z__ReadOnlyArray<string>(array2));
				List<string> mapVisitedNodesAction = AtOManager.Instance.mapVisitedNodesAction;
				string[] array4 = __state[1];
				int num2 = 0;
				string[] array5 = new string[array4.Length];
				string[] array6 = array4;
				foreach (string text in array6)
				{
					array5[num2] = text;
					num2++;
				}
				mapVisitedNodesAction.AddRange(new <>z__ReadOnlyArray<string>(array5));
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GetTownTier")]
		public static void GetTownTier(ref AtOManager __instance, ref int ___townTier, ref int __result)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge())
			{
				__result = Math.Min(___townTier, 3);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "GetActNumberForText")]
		public static void GetActNumberForText(ref AtOManager __instance, ref int ___townTier, ref int __result)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge())
			{
				__result = ___townTier + 1;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MapManager), "Awake")]
		public static void Awake(ref MapManager __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			if (refreshed)
			{
				return;
			}
			foreach (GameObject map in __instance.mapList)
			{
				foreach (Transform item in map.transform)
				{
					Transform val = item;
					if (!(((Object)((Component)val).gameObject).name == "Nodes"))
					{
						continue;
					}
					foreach (Transform item2 in val)
					{
						Transform val2 = item2;
						GameObject gameObject = ((Component)val2).gameObject;
						Node component = gameObject.GetComponent<Node>();
						((Component)component).GetComponent<Node>().nodeData = Globals.Instance.GetNodeData(component.nodeData.NodeId);
					}
				}
			}
			refreshed = true;
		}

		public static string[] GetEnabledPerks()
		{
			List<string> list = new List<string>();
			foreach (List<string> value in AtOManager.Instance.heroPerks.Values)
			{
				foreach (string item in value)
				{
					if (item.StartsWith("endless_") && !list.Contains(item))
					{
						list.Add(item);
					}
				}
			}
			return list.ToArray();
		}

		public static string GetRandomPerkDescription(PerkData perkData)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Invalid comparison between Unknown and I4
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Invalid comparison between Unknown and I4
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Invalid comparison between Unknown and I4
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			if (perkData.MaxHealth != 0)
			{
				stringBuilder.Append($"<sprite name=heart><space=.5>Health {perkData.MaxHealth:+#;-#;0}<space=1.5>");
			}
			if (perkData.SpeedQuantity != 0)
			{
				stringBuilder.Append($"<sprite name=speedMini><space=.5>Speed {perkData.SpeedQuantity:+#;-#;0}<space=1.5>");
			}
			if ((Object)(object)perkData.AuracurseBonus != (Object)null && perkData.AuracurseBonusValue != 0)
			{
				stringBuilder.Append($"<sprite name={((Object)perkData.AuracurseBonus.Sprite).name}><space=.5>charges {perkData.AuracurseBonusValue:+#;-#;0}<space=1.5>");
			}
			DamageType val;
			if (perkData.ResistModifiedValue != 0)
			{
				if ((int)perkData.ResistModified == 10)
				{
					stringBuilder.Append($"<sprite name=ui_resistance><space=.5>All resistances {perkData.ResistModifiedValue:+#;-#;0}%<space=1.5>");
				}
				if ((int)perkData.ResistModified != 10)
				{
					val = perkData.ResistModified;
					string text = ((object)(DamageType)(ref val)).ToString().ToLower();
					if (text == "slashing")
					{
						text = "slash";
					}
					stringBuilder.Append($"<sprite name=resist_{text}><space=.5>resistance {perkData.ResistModifiedValue:+#;-#;0}%<space=1.5>");
				}
			}
			if (perkData.DamageFlatBonusValue != 0)
			{
				if ((int)perkData.DamageFlatBonus == 10)
				{
					stringBuilder.Append($"<sprite name=damage><space=.5>All damage {perkData.DamageFlatBonusValue:+#;-#;0}<space=1.5>");
				}
				if ((int)perkData.DamageFlatBonus != 10)
				{
					val = perkData.DamageFlatBonus;
					string text2 = ((object)(DamageType)(ref val)).ToString().ToLower();
					if (text2 == "slashing")
					{
						text2 = "slash";
					}
					stringBuilder.Append($"<sprite name={text2}><space=.5>damage {perkData.DamageFlatBonusValue:+#;-#;0}<space=1.5>");
				}
			}
			stringBuilder.Replace("<c>", "");
			stringBuilder.Replace("</c>", "");
			return $"<space=1>{stringBuilder}";
		}

		public static string GetRandomPerkType(string[] exclude)
		{
			List<string> list = new List<string>();
			list.AddRange(new string[5] { "h", "a", "d", "r", "s" }.Where((string v) => !exclude.Contains(v)));
			string[] array = list.ToArray();
			return array[Random.Range(0, array.Length)];
		}

		public static string GetRandomPerkSubtype(string type)
		{
			if (type == "a")
			{
				string[] array = new string[16]
				{
					"bleed", "block", "burn", "chill", "dark", "fury", "insane", "poison", "regeneration", "sharp",
					"shield", "sight", "spark", "thorns", "vitality", "wet"
				};
				return array[Random.Range(0, array.Length)];
			}
			if (type == "d" || type == "r")
			{
				List<DamageType> list = new List<DamageType>();
				list.AddRange(from DamageType d in Enum.GetValues(typeof(DamageType))
					where !((object)(DamageType)(ref d)).Equals((object)(DamageType)0)
					select d);
				DamageType[] array2 = list.ToArray();
				return ((object)(DamageType)(ref array2[Random.Range(0, array2.Length)])).ToString().ToLower();
			}
			return "";
		}

		public static int GetRandomPerkValue(string type, string subtype = "")
		{
			int num = 0;
			int num2 = 0;
			if (type == "h")
			{
				num2 = 5;
				num = 15;
			}
			if (type == "a")
			{
				num2 = 1;
				num = 2;
			}
			if (type == "s")
			{
				num2 = 1;
				num = 2;
			}
			if (type == "d")
			{
				num2 = 1;
				num = 3;
			}
			if (type == "r")
			{
				num2 = 5;
				num = 10;
			}
			return Random.Range(num2, num);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EventManager), "SetEvent")]
		public static void SetEvent(ref EventManager __instance, EventData _eventData)
		{
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_080c: Unknown result type (might be due to invalid IL or missing references)
			//IL_080f: Invalid comparison between Unknown and I4
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_0633: Invalid comparison between Unknown and I4
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_065b: Invalid comparison between Unknown and I4
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Invalid comparison between Unknown and I4
			//IL_0967: Unknown result type (might be due to invalid IL or missing references)
			//IL_096a: Invalid comparison between Unknown and I4
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Invalid comparison between Unknown and I4
			//IL_0b75: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Invalid comparison between Unknown and I4
			//IL_0b9c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9f: Invalid comparison between Unknown and I4
			//IL_06f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f4: Invalid comparison between Unknown and I4
			//IL_0bc4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc7: Invalid comparison between Unknown and I4
			//IL_09ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_09af: Invalid comparison between Unknown and I4
			//IL_0bec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bef: Invalid comparison between Unknown and I4
			//IL_0c15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c19: Invalid comparison between Unknown and I4
			//IL_09f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f4: Invalid comparison between Unknown and I4
			//IL_0c3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c43: Invalid comparison between Unknown and I4
			//IL_0d5a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5d: Invalid comparison between Unknown and I4
			//IL_0e81: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d83: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d86: Invalid comparison between Unknown and I4
			//IL_0a36: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a39: Invalid comparison between Unknown and I4
			//IL_0dac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0daf: Invalid comparison between Unknown and I4
			//IL_0dd5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd8: Invalid comparison between Unknown and I4
			//IL_0dfb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dff: Invalid comparison between Unknown and I4
			//IL_0a7b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7f: Invalid comparison between Unknown and I4
			//IL_0e22: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e26: Invalid comparison between Unknown and I4
			//IL_0e49: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e4c: Invalid comparison between Unknown and I4
			//IL_0ac1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac5: Invalid comparison between Unknown and I4
			//IL_0b07: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0a: Invalid comparison between Unknown and I4
			if (_eventData.EventId == "e_endless_perk")
			{
				EventReplyData val = Globals.Instance.GetEventData("e_challenge_next").Replys.First();
				int deterministicHashCode = Functions.GetDeterministicHashCode(AtOManager.Instance.GetGameId());
				Random.InitState(deterministicHashCode);
				List<EventReplyData> list = new List<EventReplyData>();
				for (int i = 0; i < 5; i++)
				{
					EventReplyData val2 = val.ShallowCopy();
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append("endless_");
					List<string> list2 = new List<string>();
					for (int j = 0; j < 2; j++)
					{
						string randomPerkType = GetRandomPerkType(list2.ToArray());
						list2.Add(randomPerkType);
						string randomPerkSubtype = GetRandomPerkSubtype(randomPerkType);
						int randomPerkValue = GetRandomPerkValue(randomPerkType, randomPerkSubtype);
						stringBuilder.Append(randomPerkType + ":");
						if (randomPerkSubtype != "")
						{
							stringBuilder.Append(randomPerkSubtype + "#" + randomPerkType + "v:");
						}
						stringBuilder.Append($"{randomPerkValue}#");
					}
					stringBuilder.Length--;
					stringBuilder.Append("_" + Functions.RandomString(6f, 0f));
					val2.SsPerkData = Globals.Instance.GetPerkData(stringBuilder.ToString());
					val2.SsPerkData1 = null;
					val2.ReplyText = GetRandomPerkDescription(val2.SsPerkData);
					val2.SsRewardText = "";
					val2.SsRequirementUnlock = null;
					val2.SsDustReward = 0;
					val2.SsExperienceReward = 0;
					val2.SsGoldReward = 0;
					val2.SsFinishObeliskMap = false;
					val2.SsEvent = (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_pick_blessing"), "") ? Globals.Instance.GetEventData("e_endless_blessing") : Globals.Instance.GetEventData("e_endless_obelisk"));
					list.Add(val2);
				}
				Globals.Instance.GetEventData("e_endless_perk").Replys = list.ToArray();
			}
			if (_eventData.EventId == "e_endless_blessing")
			{
				EventReplyData val3 = Globals.Instance.GetEventData("e_challenge_next").Replys.First();
				int deterministicHashCode2 = Functions.GetDeterministicHashCode(AtOManager.Instance.GetGameId());
				Random.InitState(deterministicHashCode2);
				List<EventReplyData> list3 = new List<EventReplyData>();
				List<string> list4 = new List<string>();
				for (int k = 0; k < 3; k++)
				{
					CardData randomBlessing = GetRandomBlessing(list4);
					if ((Object)(object)randomBlessing != (Object)null)
					{
						list4.Add(randomBlessing.Id);
						EventReplyData val4 = val3.ShallowCopy();
						val4.SsPerkData = null;
						val4.SsPerkData1 = null;
						val4.SsAddCard1 = randomBlessing;
						val4.ReplyShowCard = randomBlessing;
						val4.ReplyText = randomBlessing.CardName;
						val4.SsRewardText = "";
						val4.SsRequirementUnlock = null;
						val4.SsDustReward = 0;
						val4.SsExperienceReward = 0;
						val4.SsGoldReward = 0;
						val4.SsFinishObeliskMap = false;
						val4.SsEvent = Globals.Instance.GetEventData("e_endless_obelisk");
						list3.Add(val4);
					}
				}
				if (list3.Count == 0)
				{
					EventReplyData val5 = val3.ShallowCopy();
					val5.SsPerkData = null;
					val5.SsPerkData1 = null;
					val5.ReplyText = "None left";
					val5.SsRewardText = "";
					val5.SsRequirementUnlock = null;
					val5.SsDustReward = 0;
					val5.SsExperienceReward = 0;
					val5.SsGoldReward = 0;
					val5.SsFinishObeliskMap = false;
					val5.SsEvent = Globals.Instance.GetEventData("e_endless_obelisk");
					list3.Add(val5);
				}
				Globals.Instance.GetEventData("e_endless_blessing").Replys = list3.ToArray();
			}
			if (!(_eventData.EventId == "e_endless_obelisk"))
			{
				return;
			}
			EventReplyData val6 = Globals.Instance.GetEventData("e_sen34_a").Replys.First();
			Zone mapZone = AtOManager.Instance.GetMapZone(AtOManager.Instance.currentMapNode);
			int deterministicHashCode3 = Functions.GetDeterministicHashCode(AtOManager.Instance.GetGameId());
			Random.InitState(deterministicHashCode3);
			bool flag = SteamManager.Instance.PlayerHaveDLC("2511580") || (GameManager.Instance.IsMultiplayer() && NetworkManager.Instance.AnyPlayersHaveSku("2511580"));
			bool flag2 = SteamManager.Instance.PlayerHaveDLC("3185630") || (GameManager.Instance.IsMultiplayer() && NetworkManager.Instance.AnyPlayersHaveSku("3185630"));
			List<NodeData> list5 = new List<NodeData>();
			list5.Add(Globals.Instance.GetNodeData("sen_0"));
			list5.Add(Globals.Instance.GetNodeData("faen_0"));
			list5.Add(Globals.Instance.GetNodeData("aqua_0"));
			list5.Add(Globals.Instance.GetNodeData("velka_0"));
			if (flag)
			{
				list5.Add(Globals.Instance.GetNodeData("ulmin_0"));
			}
			if (flag2)
			{
				list5.Add(Globals.Instance.GetNodeData("sahti_0"));
			}
			list5.Add(Globals.Instance.GetNodeData("voidlow_0"));
			bool flag3 = false;
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_unique_zones"), "") && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sen"), "") || (int)mapZone == 0) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_faen"), "") || (int)mapZone == 3) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_aqua"), "") || (int)mapZone == 2) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_velka"), "") || (int)mapZone == 1) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_ulmin"), "") || (int)mapZone == 12) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sahti"), "") || (int)mapZone == 14) && (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_void"), "") || (int)mapZone == 5))
			{
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_sen"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_faen"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_aqua"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_velka"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_ulmin"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_sahti"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_void"), "");
				flag3 = true;
			}
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_require_all_before_void"), "") && (int)mapZone == 5)
			{
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_sen"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_faen"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_aqua"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_velka"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_ulmin"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_sahti"), "");
				AtOManager.Instance.RemovePlayerRequirement(Globals.Instance.GetRequirementData("endless_complete_void"), "");
				flag3 = true;
			}
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_unique_zones"), "") || !AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_repeats"), ""))
			{
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sen"), "") || (int)mapZone == 0)
				{
					list5.Remove(Globals.Instance.GetNodeData("sen_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_faen"), "") || (int)mapZone == 3)
				{
					list5.Remove(Globals.Instance.GetNodeData("faen_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_aqua"), "") || (int)mapZone == 2)
				{
					list5.Remove(Globals.Instance.GetNodeData("aqua_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_velka"), "") || (int)mapZone == 1)
				{
					list5.Remove(Globals.Instance.GetNodeData("velka_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_ulmin"), "") || (int)mapZone == 12)
				{
					list5.Remove(Globals.Instance.GetNodeData("ulmin_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sahti"), "") || (int)mapZone == 14)
				{
					list5.Remove(Globals.Instance.GetNodeData("sahti_0"));
				}
				if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_void"), "") || (int)mapZone == 5)
				{
					list5.Remove(Globals.Instance.GetNodeData("voidlow_0"));
				}
			}
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_require_all_before_void"), "") && ((!AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sen"), "") && (int)mapZone != 0) || (!AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_faen"), "") && (int)mapZone != 3) || (!AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_aqua"), "") && (int)mapZone != 2) || (!AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_velka"), "") && (int)mapZone != 1) || (flag && !AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_ulmin"), "") && (int)mapZone != 12) || (flag2 && !AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_complete_sahti"), "") && (int)mapZone != 14)))
			{
				list5.Remove(Globals.Instance.GetNodeData("voidlow_0"));
			}
			List<EventReplyData> list6 = new List<EventReplyData>();
			int num = -1;
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_zonecount_1"), ""))
			{
				num = 1;
			}
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_zonecount_2"), ""))
			{
				num = 2;
			}
			if (AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_zonecount_3"), ""))
			{
				num = 3;
			}
			int num2 = ((num == -1) ? list5.Count : Math.Min(list5.Count, num));
			for (int l = 0; l < num2; l++)
			{
				NodeData val7 = list5[Random.Range(0, list5.Count)];
				EventReplyData val8 = val6.ShallowCopy();
				val8.ReplyActionText = (EventAction)0;
				val8.SsRequirementUnlock = null;
				if (!flag3)
				{
					if ((int)mapZone == 0)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_sen");
					}
					else if ((int)mapZone == 3)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_faen");
					}
					else if ((int)mapZone == 2)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_aqua");
					}
					else if ((int)mapZone == 1)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_velka");
					}
					else if ((int)mapZone == 12)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_ulmin");
					}
					else if ((int)mapZone == 14)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_sahti");
					}
					else if ((int)mapZone == 5)
					{
						val8.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_complete_void");
					}
				}
				val8.ReplyText = ((num == 1) ? "You are thrust into a portal of unknown color" : GetPortalString(AtOManager.Instance.GetMapZone(val7.NodeId)));
				val8.SsRewardText = "";
				val8.SsNodeTravel = val7;
				list6.Add(val8);
				list5.Remove(val7);
			}
			Globals.Instance.GetEventData("e_endless_obelisk").Replys = list6.ToArray();
		}

		public static string GetPortalString(Zone zone)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return "Step into the " + DictionaryExtensions.Get<Zone, string>((IDictionary<Zone, string>)portalStrings, zone, (string)null) + " portal.";
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EventManager), "FinalResolution")]
		public static void FinalResolutionPre(EventManager __instance, EventData ___currentEvent, EventReplyData ___replySelected)
		{
			if (!(___currentEvent.EventId == "e_endless_blessing") || ___replySelected == null)
			{
				return;
			}
			CardData ssAddCard = ___replySelected.SsAddCard1;
			Plugin.LogInfo("Selected blessing: " + ssAddCard.Id);
			activeBlessings.Add(ssAddCard.Id);
			if ((Object)(object)ssAddCard != (Object)null)
			{
				activeBlessings.Add(ssAddCard.Id);
				if ((Object)(object)ssAddCard.Item != (Object)null && ssAddCard.Item.MaxHealth > 0)
				{
					Hero[] team = AtOManager.Instance.GetTeam();
					for (int i = 0; i < 4; i++)
					{
						if (team[i] != null && (Object)(object)((Character)team[i]).HeroData != (Object)null)
						{
							Hero obj = team[i];
							((Character)obj).Hp = ((Character)obj).Hp + ssAddCard.Item.MaxHealth;
							Hero obj2 = team[i];
							((Character)obj2).HpCurrent = ((Character)obj2).HpCurrent + ssAddCard.Item.MaxHealth;
							((Character)team[i]).SetHP();
							((Character)team[i]).ClearCaches();
						}
					}
				}
			}
			___replySelected.SsAddCard1 = null;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EventManager), "FinalResolution")]
		public static void FinalResolutionPost(EventManager __instance, EventData ___currentEvent, EventReplyData ___replySelected)
		{
			if (___currentEvent.EventId == "e_endless_perk" && ___replySelected != null)
			{
				__instance.result.text = GetRandomPerkDescription(___replySelected.SsPerkData);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "GetPerkData")]
		public static void GetPerkData(Globals __instance, ref PerkData __result, ref Dictionary<string, PerkData> ____PerksSource, string id)
		{
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__result == (Object)null) || !id.StartsWith("endless_"))
			{
				return;
			}
			__result = ScriptableObject.CreateInstance<PerkData>();
			__result.Icon = Globals.Instance.GetAuraCurseData("burn").Sprite;
			__result.Id = id.ToLower();
			string[] array = id.Split(new char[1] { '_' });
			string text = array[1];
			string[] array2 = text.Split(new char[1] { '#' });
			foreach (string text2 in array2)
			{
				string[] array3 = text2.Split(new char[1] { ':' });
				string text3 = array3[0];
				string text4 = array3[1];
				switch (text3)
				{
				case "h":
					__result.MaxHealth = int.Parse(text4);
					break;
				case "s":
					__result.SpeedQuantity = int.Parse(text4);
					break;
				case "a":
					__result.AuracurseBonus = Globals.Instance.GetAuraCurseData(text4);
					break;
				case "av":
					__result.AuracurseBonusValue = int.Parse(text4);
					break;
				case "d":
					__result.DamageFlatBonus = (DamageType)Enum.Parse(typeof(DamageType), $"{char.ToUpper(text4[0])}{text4.Substring(1).ToLower()}");
					break;
				case "dv":
					__result.DamageFlatBonusValue = int.Parse(text4);
					break;
				case "r":
					__result.ResistModified = (DamageType)Enum.Parse(typeof(DamageType), $"{char.ToUpper(text4[0])}{text4.Substring(1).ToLower()}");
					break;
				case "rv":
					__result.ResistModifiedValue = int.Parse(text4);
					break;
				case "e":
					__result.EnergyBegin = int.Parse(text4);
					break;
				}
			}
			__result.Init();
			____PerksSource.Add(__result.Id, __result);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AtOManager), "AddPerkToHero")]
		public static void AddPerkToHeroPost(AtOManager __instance, ref Hero[] ___teamAtO, int _heroIndex, string _perkId, bool _initHealth)
		{
			PerkData perkData = Globals.Instance.GetPerkData(_perkId);
			if ((Object)(object)perkData != (Object)null)
			{
				string subclassName = ((Character)___teamAtO[_heroIndex]).SubclassName;
			}
		}

		public static void AddNewRequirement(string id, ref Dictionary<string, EventRequirementData> ____Requirements)
		{
			if (____Requirements.TryGetValue("_tier2", out var value))
			{
				EventRequirementData val = Object.Instantiate<EventRequirementData>(value);
				string requirementId = (((Object)val).name = id);
				val.RequirementId = requirementId;
				____Requirements.Add(val.RequirementId.ToLower(), val);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CardItem), "SetCard")]
		public static void SetCard(CardItem __instance, string id, bool deckScale, Hero _theHero, NPC _theNPC, bool GetFromGlobal, bool _generated, ref CardData ___cardData, ref Transform ___targetTextT, ref Transform ___targetT, ref Transform ___requireTextT, ref Transform ___typeText, ref Transform ___typeTextImage, ref Transform ___descriptionTextT, ref TMP_Text ___descriptionTextTM)
		{
			//IL_0004: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (___cardData.CardType == blessingCardType)
			{
				if (((Component)___targetTextT).gameObject.activeSelf)
				{
					((Component)___targetTextT).gameObject.SetActive(false);
				}
				if (((Component)___targetT).gameObject.activeSelf)
				{
					((Component)___targetT).gameObject.SetActive(false);
				}
				if (((Component)___requireTextT).gameObject.activeSelf)
				{
					((Component)___requireTextT).gameObject.SetActive(false);
				}
				if (((Component)___typeText).gameObject.activeSelf)
				{
					((Component)___typeText).gameObject.SetActive(false);
				}
				if (((Component)___typeTextImage).gameObject.activeSelf)
				{
					((Component)___typeTextImage).gameObject.SetActive(false);
				}
				___descriptionTextT.localPosition = new Vector3(___descriptionTextT.localPosition.x, -0.63f, ___descriptionTextT.localPosition.z);
				___descriptionTextTM.margin = new Vector4(0.02f, -0.02f, 0.02f, -0.04f);
			}
		}

		public static CardData AddNewCard(string id, string baseId, ref Dictionary<string, CardData> ____CardsSource, ref Dictionary<string, CardData> ____Cards)
		{
			if (____CardsSource.TryGetValue(baseId, out var value))
			{
				Plugin.LogInfo("Adding new card: " + id + " from " + baseId);
				CardData val = Object.Instantiate<CardData>(value);
				val.Id = id;
				val.InternalId = id;
				if ((Object)(object)val.Item != (Object)null)
				{
					val.Item = Object.Instantiate<ItemData>(val.Item);
					val.Item.Id = id;
				}
				if ((Object)(object)val.ItemEnchantment != (Object)null)
				{
					val.ItemEnchantment = Object.Instantiate<ItemData>(val.ItemEnchantment);
					val.ItemEnchantment.Id = id;
				}
				____CardsSource.Add(val.Id.ToLower(), val);
				____Cards.Add(val.Id.ToLower(), val);
				return val;
			}
			return null;
		}

		private static void InitNewCard(CardData 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.InitClone(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.InitClone2();
			newCard.SetDescriptionNew(true, (Character)null, true);
		}

		public static CardData CloneBlessingCard(string cardId, bool isBlessing, ref Dictionary<string, CardData> ____CardsSource, ref Dictionary<string, CardData> ____Cards, 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Invalid comparison between Unknown and I4
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Invalid comparison between Unknown and I4
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Invalid comparison between Unknown and I4
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Invalid comparison between Unknown and I4
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Invalid comparison between Unknown and I4
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Invalid comparison between Unknown and I4
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Invalid comparison between Unknown and I4
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Invalid comparison between Unknown and I4
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Invalid comparison between Unknown and I4
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Invalid comparison between Unknown and I4
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Invalid comparison between Unknown and I4
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Invalid comparison between Unknown and I4
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Invalid comparison between Unknown and I4
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Invalid comparison between Unknown and I4
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Invalid comparison between Unknown and I4
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Invalid comparison between Unknown and I4
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			if (____Cards.TryGetValue("endless" + cardId, out var value))
			{
				Plugin.LogInfo("Got existing card: " + value.Id);
				return value;
			}
			Plugin.LogInfo("Creating blessing card endless" + cardId);
			CardData val = AddNewCard("endless" + cardId, cardId, ref ____CardsSource, ref ____Cards);
			val.CardName = "Blessing: " + val.CardName;
			if (isBlessing)
			{
				val.CardType = blessingCardType;
			}
			val.CardClass = (CardClass)9;
			ItemData val2 = val.Item ?? val.ItemEnchantment;
			if ((Object)(object)val2 != (Object)null)
			{
				if ((int)val2.CastedCardType > 0)
				{
					val2.CastedCardType = (CardType)0;
				}
				if ((int)val2.ItemTarget == 4)
				{
					val2.ItemTarget = (ItemTarget)3;
				}
				else if ((int)val2.ItemTarget == 3)
				{
					val2.ItemTarget = (ItemTarget)4;
				}
				if ((int)val2.ItemTarget == 2)
				{
					val2.ItemTarget = (ItemTarget)1;
				}
				else if ((int)val2.ItemTarget == 1)
				{
					val2.ItemTarget = (ItemTarget)2;
				}
				if ((int)val2.ItemTarget == 10)
				{
					val2.ItemTarget = (ItemTarget)8;
				}
				else if ((int)val2.ItemTarget == 8)
				{
					val2.ItemTarget = (ItemTarget)10;
				}
				if ((int)val2.ItemTarget == 9)
				{
					val2.ItemTarget = (ItemTarget)7;
				}
				else if ((int)val2.ItemTarget == 7)
				{
					val2.ItemTarget = (ItemTarget)9;
				}
				if ((int)val2.ItemTarget == 0)
				{
					val2.ItemTarget = (ItemTarget)6;
				}
				else if ((int)val2.ItemTarget == 6)
				{
					val2.ItemTarget = (ItemTarget)0;
				}
				if ((int)val2.CardPlace == 1 && val2.CardNum > 0)
				{
					val2.CardPlace = (CardPlace)5;
				}
				if ((int)val2.CardPlace == 5 && val2.CardNum > 0 && ((int)val2.Activation == 2 || (int)val2.Activation == 28))
				{
					val2.Activation = (EventActivation)22;
				}
				if (val2.CardNum == 0 && (int)val2.Activation == 28)
				{
					val2.Activation = blessingBeginRound;
				}
				if (val2.CardNum == 0 && (int)val2.Activation == 27)
				{
					val2.Activation = blessingCombatStart;
				}
				if ((Object)(object)val2.CardToGain != (Object)null)
				{
					val2.CardToGain = CloneBlessingCard(val2.CardToGain.Id, isBlessing: false, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
					val2.CardToGain.Playable = true;
					if (val.RelatedCard != "")
					{
						val.RelatedCard = val2.CardToGain.Id;
					}
				}
				else if (val2.CardToGainList != null && val2.CardToGainList.Count > 0)
				{
					List<CardData> list = new List<CardData>();
					foreach (CardData cardToGain in val2.CardToGainList)
					{
						CardData val3 = CloneBlessingCard(cardToGain.Id, isBlessing: false, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
						val3.Playable = true;
						list.Add(val3);
					}
					val2.CardToGainList = list;
					if (val2.CardToGainList.Count > 0 && val.RelatedCard != "")
					{
						val.RelatedCard = val2.CardToGainList[0].Id;
					}
					if (val2.CardToGainList.Count > 1 && val.RelatedCard2 != "")
					{
						val.RelatedCard2 = val2.CardToGainList[1].Id;
					}
					if (val2.CardToGainList.Count > 2 && val.RelatedCard3 != "")
					{
						val.RelatedCard3 = val2.CardToGainList[2].Id;
					}
				}
				if ((Object)(object)val.ItemEnchantment != (Object)null)
				{
					val.ItemEnchantment = val2;
				}
				else
				{
					val.Item = val2;
				}
			}
			Traverse.Create((object)val).Field("descriptionId").SetValue((object)"");
			Traverse.Create((object)val).Field("effectRequired").SetValue((object)"");
			if (val.UpgradedFrom != "")
			{
				val.UpgradedFrom = "endless" + val.UpgradedFrom.ToLower();
			}
			if (val.UpgradesTo1 != "")
			{
				CardData val4 = CloneBlessingCard(val.UpgradesTo1.ToLower(), isBlessing: true, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				val.UpgradesTo1 = val4.Id;
			}
			if (val.UpgradesTo2 != "")
			{
				CardData val5 = CloneBlessingCard(val.UpgradesTo2.ToLower(), isBlessing: true, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				val.UpgradesTo2 = val5.Id;
			}
			if ((Object)(object)val.UpgradesToRare != (Object)null)
			{
				CardData upgradesToRare = CloneBlessingCard(val.UpgradesToRare.Id, isBlessing: true, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				val.UpgradesToRare = upgradesToRare;
			}
			InitNewCard(val, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
			return val;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "GetExperienceByLevel")]
		public static void GetExperienceByLevel(ref Globals __instance, int level, ref int __result)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge() && AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), ""))
			{
				if (level == 5)
				{
					__result = 2250;
				}
				if (level == 6)
				{
					__result = 3000;
				}
				if (level == 7)
				{
					__result = 4000;
				}
				if (level == 8)
				{
					__result = 6000;
				}
				if (level >= 9)
				{
					__result = 99999;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "CalculateRewardForCharacter")]
		public static void CalculateRewardForCharacter(ref Character __instance, ref int _experience, ref int __result)
		{
			if (GameManager.Instance.IsObeliskChallenge() || GameManager.Instance.IsWeeklyChallenge() || !AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), ""))
			{
				return;
			}
			int num = AtOManager.Instance.GetActNumberForText("") - 1;
			if (num >= 5)
			{
				if (AtOManager.Instance.IsChallengeTraitActive("smartheroes"))
				{
					_experience += Functions.FuncRoundToInt((float)_experience * 0.5f);
				}
				float num2 = 0.1f;
				if (__instance.Level > AtOManager.Instance.GetActNumberForText(""))
				{
					__result = Functions.FuncRoundToInt((float)_experience * num2);
				}
				else if (__instance.Experience >= Globals.Instance.GetExperienceByLevel(__instance.Level))
				{
					__result = Functions.FuncRoundToInt((float)_experience * num2);
				}
				else if (__instance.Experience + _experience > Globals.Instance.GetExperienceByLevel(__instance.Level))
				{
					int num3 = _experience - (Globals.Instance.GetExperienceByLevel(__instance.Level) - __instance.Experience);
					__result = Globals.Instance.GetExperienceByLevel(__instance.Level) - __instance.Experience + Functions.FuncRoundToInt((float)num3 * num2);
				}
				else
				{
					__result = _experience;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(OverCharacter), "DoStats")]
		public static void DoStats(ref OverCharacter __instance, ref Hero ___hero)
		{
			if (!GameManager.Instance.IsObeliskChallenge() && !GameManager.Instance.IsWeeklyChallenge() && AtOManager.Instance.PlayerHasRequirement(Globals.Instance.GetRequirementData("endless_allow_additional_levels"), ""))
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("L");
				stringBuilder.Append(((Character)___hero).Level);
				if (((Character)___hero).Level < 9)
				{
					stringBuilder.Append("  <voffset=.15><size=-.5><color=#FFC086>[");
					stringBuilder.Append(((Character)___hero).Experience);
					stringBuilder.Append("/");
					stringBuilder.Append(Globals.Instance.GetExperienceByLevel(((Character)___hero).Level));
					stringBuilder.Append("]");
				}
				__instance.experienceText.text = stringBuilder.ToString();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "CreateGameContent")]
		public static void CreateGameContent(ref Globals __instance, ref Dictionary<string, EventData> ____Events, ref Dictionary<string, NodeData> ____NodeDataSource, ref Dictionary<string, CombatData> ____CombatDataSource, ref Dictionary<string, CinematicData> ____Cinematics, ref Dictionary<string, EventRequirementData> ____Requirements, ref Dictionary<string, CardData> ____CardsSource, ref Dictionary<string, CardData> ____Cards, 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)
		{
			if (GameManager.Instance.IsObeliskChallenge() || GameManager.Instance.IsWeeklyChallenge())
			{
				return;
			}
			foreach (string blessingCard in blessingCards)
			{
				CardData val = CloneBlessingCard(blessingCard, isBlessing: true, ref ____CardsSource, ref ____Cards, ref ____CardItemByType, ref ____CardListByType, ref ____CardListByClass, ref ____CardListNotUpgraded, ref ____CardListNotUpgradedByClass, ref ____CardListByClassType, ref ____CardEnergyCost);
				availableBlessings.Add(val.Id);
			}
			GameManager.Instance.cardSprites = GameManager.Instance.cardSprites.Concat(GameManager.Instance.cardSprites.Where((Sprite c) => ((Object)c).name == "card-bg-special")).ToArray();
			AddNewRequirement("endless_complete_sen", ref ____Requirements);
			AddNewRequirement("endless_complete_faen", ref ____Requirements);
			AddNewRequirement("endless_complete_aqua", ref ____Requirements);
			AddNewRequirement("endless_complete_ulmin", ref ____Requirements);
			AddNewRequirement("endless_complete_velka", ref ____Requirements);
			AddNewRequirement("endless_complete_sahti", ref ____Requirements);
			AddNewRequirement("endless_complete_void", ref ____Requirements);
			AddNewRequirement("endless_unique_zones", ref ____Requirements);
			AddNewRequirement("endless_allow_repeats", ref ____Requirements);
			AddNewRequirement("endless_require_all_before_void", ref ____Requirements);
			AddNewRequirement("endless_allow_perks", ref ____Requirements);
			AddNewRequirement("endless_allow_blessings", ref ____Requirements);
			AddNewRequirement("endless_allow_blessings_starting_4", ref ____Requirements);
			AddNewRequirement("endless_allow_blessings_every_4", ref ____Requirements);
			AddNewRequirement("endless_allow_blessings_after_void", ref ____Requirements);
			AddNewRequirement("endless_pick_blessing", ref ____Requirements);
			AddNewRequirement("endless_allow_additional_levels", ref ____Requirements);
			AddNewRequirement("endless_zonecount_1", ref ____Requirements);
			AddNewRequirement("endless_zonecount_2", ref ____Requirements);
			AddNewRequirement("endless_zonecount_3", ref ____Requirements);
			if (____Events.TryGetValue("e_sen44_a", out var value))
			{
				EventData val2 = Object.Instantiate<EventData>(value);
				EventData val3 = Object.Instantiate<EventData>(value);
				EventData val4 = Object.Instantiate<EventData>(value);
				EventData val5 = Object.Instantiate<EventData>(value);
				EventData val6 = Object.Instantiate<EventData>(value);
				EventData val7 = Object.Instantiate<EventData>(value);
				EventData val8 = Object.Instantiate<EventData>(value);
				EventReplyData val9 = Globals.Instance.GetEventData("e_sen44_a").Replys.First();
				EventReplyData val10 = val9.ShallowCopy();
				EventReplyData val11 = val9.ShallowCopy();
				val10.ReplyActionText = (EventAction)0;
				val10.ReplyText = "Yes";
				val10.SsRewardText = "";
				val10.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_perks");
				val10.SsEvent = val3;
				val11.ReplyActionText = (EventAction)0;
				val11.ReplyText = "No";
				val11.SsRewardText = "";
				val11.SsRequirementUnlock = null;
				val11.SsEvent = val3;
				EventReplyData val12 = val9.ShallowCopy();
				EventReplyData val13 = val9.ShallowCopy();
				EventReplyData val14 = val9.ShallowCopy();
				EventReplyData val15 = val9.ShallowCopy();
				EventReplyData val16 = val9.ShallowCopy();
				val12.ReplyActionText = (EventAction)0;
				val12.ReplyText = "After every Act";
				val12.SsRewardText = "";
				val12.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_blessings");
				val12.SsRequirementUnlock2 = Globals.Instance.GetRequirementData("endless_pick_blessing");
				val12.SsEvent = val4;
				val13.ReplyActionText = (EventAction)0;
				val13.ReplyText = "After every Act starting at Act 4";
				val13.SsRewardText = "";
				val13.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_blessings_starting_4");
				val13.SsEvent = val4;
				val14.ReplyActionText = (EventAction)0;
				val14.ReplyText = "After every 4th Act";
				val14.SsRewardText = "";
				val14.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_blessings_every_4");
				val14.SsEvent = val4;
				val15.ReplyActionText = (EventAction)0;
				val15.ReplyText = "After every Void Act";
				val15.SsRewardText = "";
				val15.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_blessings_after_void");
				val15.SsEvent = val4;
				val16.ReplyActionText = (EventAction)0;
				val16.ReplyText = "Disable";
				val16.SsRewardText = "";
				val16.SsRequirementUnlock = null;
				val16.SsEvent = val4;
				EventReplyData val17 = val9.ShallowCopy();
				EventReplyData val18 = val9.ShallowCopy();
				val17.ReplyActionText = (EventAction)0;
				val17.ReplyText = "Yes";
				val17.SsRewardText = "";
				val17.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_additional_levels");
				val17.SsEvent = val5;
				val18.ReplyActionText = (EventAction)0;
				val18.ReplyText = "No";
				val18.SsRewardText = "";
				val18.SsRequirementUnlock = null;
				val18.SsEvent = val5;
				EventReplyData val19 = val9.ShallowCopy();
				EventReplyData val20 = val9.ShallowCopy();
				val19.ReplyActionText = (EventAction)0;
				val19.ReplyText = "Yes";
				val19.SsRewardText = "";
				val19.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_require_all_before_void");
				val19.SsEvent = val6;
				val20.ReplyActionText = (EventAction)0;
				val20.ReplyText = "No";
				val20.SsRewardText = "";
				val20.SsRequirementUnlock = null;
				val20.SsEvent = val6;
				EventReplyData val21 = val9.ShallowCopy();
				EventReplyData val22 = val9.ShallowCopy();
				val21.ReplyActionText = (EventAction)0;
				val21.ReplyText = "Yes";
				val21.SsRewardText = "";
				val21.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_unique_zones");
				val21.SsEvent = val8;
				val22.ReplyActionText = (EventAction)0;
				val22.ReplyText = "No";
				val22.SsRewardText = "";
				val22.SsRequirementUnlock = null;
				val22.SsEvent = val7;
				EventReplyData val23 = val9.ShallowCopy();
				EventReplyData val24 = val9.ShallowCopy();
				val23.ReplyActionText = (EventAction)0;
				val23.ReplyText = "Yes";
				val23.SsRewardText = "";
				val23.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_allow_repeats");
				val23.SsEvent = val8;
				val24.ReplyActionText = (EventAction)0;
				val24.ReplyText = "No";
				val24.SsRewardText = "";
				val24.SsRequirementUnlock = null;
				val24.SsEvent = val8;
				EventReplyData val25 = val9.ShallowCopy();
				EventReplyData val26 = val9.ShallowCopy();
				EventReplyData val27 = val9.ShallowCopy();
				EventReplyData val28 = val9.ShallowCopy();
				val25.ReplyActionText = (EventAction)0;
				val25.ReplyText = "1";
				val25.SsRewardText = "";
				val25.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_zonecount_1");
				val25.SsEvent = null;
				val26.ReplyActionText = (EventAction)0;
				val26.ReplyText = "2";
				val26.SsRewardText = "";
				val26.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_zonecount_2");
				val26.SsEvent = null;
				val27.ReplyActionText = (EventAction)0;
				val27.ReplyText = "3";
				val27.SsRewardText = "";
				val27.SsRequirementUnlock = Globals.Instance.GetRequirementData("endless_zonecount_3");
				val27.SsEvent = null;
				val28.ReplyActionText = (EventAction)0;
				val28.ReplyText = "All";
				val28.SsRewardText = "";
				val28.SsRequirementUnlock = null;
				val28.SsEvent = null;
				val2.EventName = "Endless Obelisk";
				val2.Description = "Allow Perks";
				val2.DescriptionAction = "Allow randomized perks at the end of each act?";
				val2.EventId = "e_endless_allow_perks";
				val2.Replys = (EventReplyData[])(object)new EventReplyData[2] { val10, val11 };
				val2.Init();
				____Events.Add(val2.EventId.ToLower(), val2);
				val3.EventName = "Endless Obelisk";
				val3.Description = "Allow Blessings";
				val3.DescriptionAction = "Allow randomized blessings at the end of acts?";
				val3.EventId = "e_endless_allow_blessings";
				val3.Replys = (EventReplyData[])(object)new EventReplyData[5] { val12, val13, val14, val15, val16 };
				val3.Init();
				____Events.Add(val3.EventId.ToLower(), val3);
				val4.EventName = "Endless Obelisk";
				val4.Description = "Allow Additional Levels";
				val4.DescriptionAction = "Allow additional levels past 5, allowing you to select traits from the other side of the tree?";
				val4.EventId = "e_endless_allow_additional_levels";
				val4.Replys = (EventReplyData[])(object)new EventReplyData[2] { val17, val18 };
				val4.Init();
				____Events.Add(val4.EventId.ToLower(), val4);
				val5.EventName = "Endless Obelisk";
				val5.Description = "Require All Before Void";
				val5.DescriptionAction = "Require all other acts to be completed per cycle before void act?";
				val5.EventId = "e_endless_require_all_before_void";
				val5.Replys = (EventReplyData[])(object)new EventReplyData[2] { val19, val20 };
				val5.Init();
				____Events.Add(val5.EventId.ToLower(), val5);
				val6.EventName = "Endless Obelisk";
				val6.Description = "Unique Zones";
				val6.DescriptionAction = "Only encounter each zone once per cycle?";
				val6.EventId = "e_endless_unique_zones";
				val6.Replys = (EventReplyData[])(object)new EventReplyData[2] { val21, val22 };
				val6.Init();
				____Events.Add(val6.EventId.ToLower(), val6);
				val7.EventName = "Endless Obelisk";
				val7.Description = "Allow Repeat Zones";
				val7.DescriptionAction = "Allow the same zone to be encountered after itself?";
				val7.EventId = "e_endless_allow_repeats";
				val7.Replys = (EventReplyData[])(object)new EventReplyData[2] { val23, val24 };
				val7.Init();
				____Events.Add(val7.EventId.ToLower(), val7);
				val8.EventName = "Endless Obelisk";
				val8.Description = "Zones to Pick From";
				val8.DescriptionAction = "How many random zones to pick from at the obelisk?";
				val8.EventId = "e_endless_zone_count";
				val8.Replys = (EventReplyData[])(object)new EventReplyData[4] { val25, val26, val27, val28 };
				val8.Init();
				____Events.Add(val8.EventId.ToLower(), val8);
			}
			if (____Events.TryGetValue("e_sen34_a", out var value2))
			{
				EventData val29 = Object.Instantiate<EventData>(value2);
				val29.EventName = "Endless Obelisk";
				val29.Description = "Ahhhhhhhhhhhhhhhhhhhh!";
				val29.DescriptionAction = "AHHHHHHHHHHHHHHHH!";
				val29.EventId = "e_endless_obelisk";
				val29.Replys = Array.Empty<EventReplyData>();
				val29.Init();
				____Events.Add(val29.EventId.ToLower(), val29);
			}
			if (____Events.TryGetValue("e_challenge_next", out var value3))
			{
				EventData val30 = Object.Instantiate<EventData>(value3);
				val30.EventName = "Endless Obelisk";
				val30.Description = "Pick yo perk";
				val30.DescriptionAction = "Choose it yo";
				val30.EventId = "e_endless_perk";
				val30.Requirement = Globals.Instance.GetRequirementData("endless_allow_perks");
				val30.Replys = Array.Empty<EventReplyData>();
				val30.ReplyRandom = 0;
				val30.Init();
				____Events.Add(val30.EventId.ToLower(), val30);
			}
			if (____Events.TryGetValue("e_challenge_next", out var value4))
			{
				EventData val31 = Object.Instantiate<EventData>(value4);
				val31.EventName = "Endless Obelisk";
				val31.Description = "Pick yo blessing";
				val31.DescriptionAction = "Choose it yo";
				val31.EventId = "e_endless_blessing";
				val31.Requirement = Globals.Instance.GetRequirementData("endless_pick_blessing");
				val31.Replys = Array.Empty<EventReplyData>();
				val31.ReplyRandom = 0;
				val31.Init();
				____Events.Add(val31.EventId.ToLower(), val31);
			}
			if (____Cinematics.TryGetValue("intro", out var value5))
			{
				value5.CinematicEvent = Globals.Instance.GetEventData("e_endless_allow_perks");
				____Cinematics["intro"] = value5;
			}
			if (____NodeDataSource.TryGetValue("sen_34", out var value6))
			{
				value6.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value6.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["sen_34"] = value6;
			}
			if (____NodeDataSource.TryGetValue("faen_39", out var value7))
			{
				value7.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value7.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["faen_39"] = value7;
			}
			if (____NodeDataSource.TryGetValue("aqua_36", out var value8))
			{
				value8.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value8.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["aqua_36"] = value8;
			}
			if (____NodeDataSource.TryGetValue("velka_33", out var value9))
			{
				value9.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value9.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["velka_33"] = value9;
			}
			if (____NodeDataSource.TryGetValue("ulmin_40", out var value10))
			{
				value10.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value10.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["ulmin_40"] = value10;
			}
			if (____NodeDataSource.TryGetValue("sahti_63", out var value11))
			{
				value11.NodeEvent = (EventData[])(object)new EventData[3]
				{
					Globals.Instance.GetEventData("e_endless_perk"),
					Globals.Instance.GetEventData("e_endless_blessing"),
					Globals.Instance.GetEventData("e_endless_obelisk")
				};
				value11.NodeEventPriority = new int[3] { 0, 1, 2 };
				____NodeDataSource["sahti_63"] = value11;
			}
			if (____CombatDataSource.TryGetValue("evoidhigh_13b", out var value12))
			{
				value12.EventData = Globals.Instance.GetEventData("e_endless_obelisk");
				____CombatDataSource["evoidhigh_13b"] = value12;
			}
			if (____Cinematics.TryGetValue("endgame", out var value13))
			{
				value13.CinematicEndAdventure = false;
				____Cinematics["endgame"] = value13;
			}
			GameManager.Instance.DebugShow();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(EventManager), "CloseEvent")]
		public static void CloseEvent(ref EventManager __instance, ref NodeData ___destinationNode, ref EventData ___currentEvent)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Invalid comparison between Unknown and I4
			if (GameManager.Instance.IsObeliskChallenge() || GameManager.Instance.IsWeeklyChallenge() || !((Object)(object)___destinationNode != (Object)null) || !(___currentEvent.EventId == "e_endless_obelisk"))
			{
				return;
			}
			AtOManager.Instance.SetTownTier(AtOManager.Instance.GetActNumberForText(""));
			AtOManager.Instance.SetGameId(string.Format("{0}+{1}", AtOManager.Instance.GetGameId().Split(new char[1] { '+' }).First(), AtOManager.Instance.GetActNumberForText("")));
			AtOManager.Instance.gameNodeAssigned.Clear();
			AtOManager.Instance.RemoveItemList(true);
			if (RemoveRequirementsByZone.TryGetValue(AtOManager.Instance.GetMapZone(___destinationNode.NodeId), out var value))
			{
				foreach