Decompiled source of KarmaClimb v1.0.0

KarmaClimb.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KarmaClimb")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1b33dbb05d38b224fd3cbcabe0d9c85c7788348c")]
[assembly: AssemblyProduct("KarmaClimb")]
[assembly: AssemblyTitle("KarmaClimb")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KarmaClimb
{
	internal static class EclipseKarmaLock
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_ModifyKarma <>9__0_0;

			internal void <Init>b__0_0(orig_ModifyKarma orig, KarmaManager self, int amount)
			{
				if (!(Run.instance is EclipseRun))
				{
					orig.Invoke(self, amount);
				}
			}
		}

		internal static void Init()
		{
			//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)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				hook_ModifyKarma val = delegate(orig_ModifyKarma orig, KarmaManager self, int amount)
				{
					if (!(Run.instance is EclipseRun))
					{
						orig.Invoke(self, amount);
					}
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			KarmaManager.ModifyKarma += (hook_ModifyKarma)obj;
		}
	}
	internal static class EclipseLadderHooks
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_GetEclipseDifficultyIndex <>9__4_0;

			public static hook_GetEclipseLevelFromRuleBook <>9__4_1;

			public static hook_OverrideRuleChoices <>9__4_2;

			public static hook_FindChoiceDef <>9__4_3;

			internal DifficultyIndex <Init>b__4_0(orig_GetEclipseDifficultyIndex orig, int eclipseLevel)
			{
				//IL_0012: 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)
				if (!KarmaClimbDifficulties.TryGetDifficultyIndex(eclipseLevel, out var index))
				{
					return orig.Invoke(eclipseLevel);
				}
				return index;
			}

			internal int <Init>b__4_1(orig_GetEclipseLevelFromRuleBook orig, RuleBook ruleBook)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				if (!KarmaClimbDifficulties.TryGetEclipseLevel(ruleBook.FindDifficulty(), out var eclipseLevel))
				{
					return orig.Invoke(ruleBook);
				}
				return eclipseLevel;
			}

			internal void <Init>b__4_2(orig_OverrideRuleChoices orig, EclipseRun self, RuleChoiceMask mustInclude, RuleChoiceMask mustExclude, ulong runSeed)
			{
				inEclipseOverride = true;
				try
				{
					orig.Invoke(self, mustInclude, mustExclude, runSeed);
				}
				finally
				{
					inEclipseOverride = false;
				}
			}

			internal RuleChoiceDef <Init>b__4_3(orig_FindChoiceDef orig, string globalName)
			{
				if (inEclipseOverride && TryRemap(orig, globalName, out var remapped))
				{
					return remapped;
				}
				return orig.Invoke(globalName);
			}
		}

		private const string DifficultyPrefix = "Difficulty.";

		private const string KarmaPrefix = "Karma.InitialLevel.";

		private const string KarmaDisabledChoice = "Karma.InitialLevel.KarmaDisabled";

		private static bool inEclipseOverride;

		internal static void Init()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0087: 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: Expected O, but got Unknown
			EclipseRun.maxEclipseLevel = 16;
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				DifficultyIndex index;
				hook_GetEclipseDifficultyIndex val = (orig_GetEclipseDifficultyIndex orig, int eclipseLevel) => (!KarmaClimbDifficulties.TryGetDifficultyIndex(eclipseLevel, out index)) ? orig.Invoke(eclipseLevel) : index;
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			EclipseRun.GetEclipseDifficultyIndex += (hook_GetEclipseDifficultyIndex)obj;
			object obj2 = <>c.<>9__4_1;
			if (obj2 == null)
			{
				int eclipseLevel;
				hook_GetEclipseLevelFromRuleBook val2 = (orig_GetEclipseLevelFromRuleBook orig, RuleBook ruleBook) => (!KarmaClimbDifficulties.TryGetEclipseLevel(ruleBook.FindDifficulty(), out eclipseLevel)) ? orig.Invoke(ruleBook) : eclipseLevel;
				<>c.<>9__4_1 = val2;
				obj2 = (object)val2;
			}
			EclipseRun.GetEclipseLevelFromRuleBook += (hook_GetEclipseLevelFromRuleBook)obj2;
			object obj3 = <>c.<>9__4_2;
			if (obj3 == null)
			{
				hook_OverrideRuleChoices val3 = delegate(orig_OverrideRuleChoices orig, EclipseRun self, RuleChoiceMask mustInclude, RuleChoiceMask mustExclude, ulong runSeed)
				{
					inEclipseOverride = true;
					try
					{
						orig.Invoke(self, mustInclude, mustExclude, runSeed);
					}
					finally
					{
						inEclipseOverride = false;
					}
				};
				<>c.<>9__4_2 = val3;
				obj3 = (object)val3;
			}
			EclipseRun.OverrideRuleChoices += (hook_OverrideRuleChoices)obj3;
			object obj4 = <>c.<>9__4_3;
			if (obj4 == null)
			{
				RuleChoiceDef remapped;
				hook_FindChoiceDef val4 = (orig_FindChoiceDef orig, string globalName) => (inEclipseOverride && TryRemap(orig, globalName, out remapped)) ? remapped : orig.Invoke(globalName);
				<>c.<>9__4_3 = val4;
				obj4 = (object)val4;
			}
			RuleCatalog.FindChoiceDef += (hook_FindChoiceDef)obj4;
		}

		private static bool TryRemap(orig_FindChoiceDef orig, string globalName, out RuleChoiceDef remapped)
		{
			//IL_0044: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected I4, but got Unknown
			remapped = null;
			if (string.IsNullOrEmpty(globalName))
			{
				return false;
			}
			if (globalName.StartsWith("Difficulty."))
			{
				string text = globalName.Substring("Difficulty.".Length);
				foreach (KeyValuePair<int, DifficultyIndex> registeredLevel in KarmaClimbDifficulties.RegisteredLevels)
				{
					if (!(((object)registeredLevel.Value/*cast due to .constrained prefix*/).ToString() != text))
					{
						remapped = FindDifficultyChoice(registeredLevel.Value);
						if (remapped == null)
						{
							Log.Error($"No rule choice for DifficultyIndex {(int)registeredLevel.Value} (Eclipse {registeredLevel.Key}).");
						}
						return remapped != null;
					}
				}
				return false;
			}
			if (globalName.StartsWith("Karma.InitialLevel."))
			{
				if (!int.TryParse(globalName.Substring("Karma.InitialLevel.".Length), out var result))
				{
					return false;
				}
				int num = KarmaClimbLadder.KarmaLevelFor(result);
				remapped = orig.Invoke((num > 0) ? ("Karma.InitialLevel." + num) : "Karma.InitialLevel.KarmaDisabled");
				return remapped != null;
			}
			return false;
		}

		private static RuleChoiceDef FindDifficultyChoice(DifficultyIndex index)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			RuleDef val = RuleCatalog.FindRuleDef("Difficulty");
			if (val == null)
			{
				return null;
			}
			foreach (RuleChoiceDef choice in val.choices)
			{
				if (choice.difficultyIndex == index)
				{
					return choice;
				}
			}
			return null;
		}
	}
	internal static class EclipseMenuDump
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Awake <>9__2_0;

			internal void <Init>b__2_0(orig_Awake orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				Dump(self);
			}
		}

		private static bool enabled;

		private static bool logged;

		internal static void Init(bool logHierarchy)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			enabled = logHierarchy;
			if (!enabled)
			{
				return;
			}
			object obj = <>c.<>9__2_0;
			if (obj == null)
			{
				hook_Awake val = delegate(orig_Awake orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					Dump(self);
				};
				<>c.<>9__2_0 = val;
				obj = (object)val;
			}
			EclipseRunScreenController.Awake += (hook_Awake)obj;
		}

		private static void Dump(EclipseRunScreenController controller)
		{
			if (!logged)
			{
				logged = true;
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("Eclipse menu hierarchy:\n");
				Append(stringBuilder, ((Component)controller).transform, 0);
				Log.Info(stringBuilder.ToString());
			}
		}

		private static void Append(StringBuilder sb, Transform transform, int depth)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//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)
			sb.Append(' ', depth * 2).Append("- ").Append(((Object)transform).name);
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				StringBuilder stringBuilder = sb.Append("  rect=");
				Rect rect = val.rect;
				StringBuilder stringBuilder2 = stringBuilder.Append(Mathf.Round(((Rect)(ref rect)).width)).Append('x');
				rect = val.rect;
				stringBuilder2.Append(Mathf.Round(((Rect)(ref rect)).height));
			}
			LayoutElement component = ((Component)transform).GetComponent<LayoutElement>();
			if (Object.op_Implicit((Object)(object)component))
			{
				sb.Append("  LE(min=").Append(component.minHeight).Append(",pref=")
					.Append(component.preferredHeight)
					.Append(",flex=")
					.Append(component.flexibleHeight)
					.Append(",ignore=")
					.Append(component.ignoreLayout)
					.Append(')');
			}
			Component[] components = ((Component)transform).GetComponents<Component>();
			if (components.Length != 0)
			{
				sb.Append("  [");
				for (int i = 0; i < components.Length; i++)
				{
					if (i > 0)
					{
						sb.Append(", ");
					}
					sb.Append(Object.op_Implicit((Object)(object)components[i]) ? ((object)components[i]).GetType().Name : "null");
				}
				sb.Append(']');
			}
			sb.Append('\n');
			for (int j = 0; j < transform.childCount; j++)
			{
				Append(sb, transform.GetChild(j), depth + 1);
			}
		}
	}
	internal class EclipseMenuEscape : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Awake <>9__1_0;

			internal void <Init>b__1_0(orig_Awake orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				if (!Object.op_Implicit((Object)(object)((Component)self).GetComponent<EclipseMenuEscape>()))
				{
					((Component)self).gameObject.AddComponent<EclipseMenuEscape>();
				}
			}
		}

		private Button backButton;

		internal static void Init()
		{
			//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)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				hook_Awake val = delegate(orig_Awake orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					if (!Object.op_Implicit((Object)(object)((Component)self).GetComponent<EclipseMenuEscape>()))
					{
						((Component)self).gameObject.AddComponent<EclipseMenuEscape>();
					}
				};
				<>c.<>9__1_0 = val;
				obj = (object)val;
			}
			EclipseRunScreenController.Awake += (hook_Awake)obj;
		}

		private void Start()
		{
			Transform val = ((Component)this).transform.Find("Main Panel/BackButton");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Button[] componentsInChildren = ((Component)this).GetComponentsInChildren<Button>(true);
				foreach (Button val2 in componentsInChildren)
				{
					if (((Object)val2).name.Contains("BackButton"))
					{
						val = ((Component)val2).transform;
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Warning("No Back button in the Eclipse menu; Escape will not leave it.");
			}
			else
			{
				backButton = ((Component)val).GetComponent<Button>();
			}
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)backButton) && Input.GetKeyDown((KeyCode)27) && ((Selectable)backButton).interactable)
			{
				((UnityEvent)backButton.onClick).Invoke();
			}
		}
	}
	internal static class EclipseMenuKarmaPanel
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Awake <>9__4_0;

			internal void <Init>b__4_0(orig_Awake orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				Build(self);
			}
		}

		internal const string PanelName = "KarmaClimbKarmaPanel";

		internal const string BadgeRowName = "KarmaBadgeRow";

		private const float GapBelowParagraph = 32f;

		private const float BadgeSpacing = 6f;

		internal static void Init()
		{
			//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)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				hook_Awake val = delegate(orig_Awake orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					Build(self);
				};
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			EclipseRunScreenController.Awake += (hook_Awake)obj;
		}

		private static void Build(EclipseRunScreenController controller)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			Transform val = ((Component)controller).transform.Find("Main Panel/GenericMenuButtonPanel");
			RectTransform val2 = (RectTransform)(Object.op_Implicit((Object)(object)val) ? /*isinst with value type is only supported in some contexts*/: null);
			EclipseDifficultyMedalDisplay componentInChildren = ((Component)controller).GetComponentInChildren<EclipseDifficultyMedalDisplay>(true);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)componentInChildren))
			{
				Log.Warning("Eclipse menu is missing the left column, its description or a medal; skipping the Karma box.");
			}
			else if (!Object.op_Implicit((Object)(object)val.Find("KarmaClimbKarmaPanel")))
			{
				GameObject val3 = new GameObject("KarmaClimbKarmaPanel", new Type[1] { typeof(RectTransform) });
				val3.transform.SetParent(val, false);
				RectTransform val4 = (RectTransform)val3.transform;
				val4.anchorMin = new Vector2(0.5f, 0.5f);
				val4.anchorMax = new Vector2(0.5f, 0.5f);
				val4.pivot = new Vector2(0f, 1f);
				Rect rect = val2.rect;
				val4.sizeDelta = new Vector2(((Rect)(ref rect)).width, 0f);
				Transform val5 = ((Component)controller).transform.Find("Main Panel/RightPanel");
				CopyBackdrop(val5, val3);
				VerticalLayoutGroup obj = val3.AddComponent<VerticalLayoutGroup>();
				VerticalLayoutGroup val6 = (Object.op_Implicit((Object)(object)val5) ? ((Component)val5).GetComponent<VerticalLayoutGroup>() : null);
				((LayoutGroup)obj).padding = (Object.op_Implicit((Object)(object)val6) ? new RectOffset(((LayoutGroup)val6).padding.left, ((LayoutGroup)val6).padding.right, ((LayoutGroup)val6).padding.top, ((LayoutGroup)val6).padding.bottom) : new RectOffset(16, 16, 16, 16));
				((HorizontalOrVerticalLayoutGroup)obj).spacing = (Object.op_Implicit((Object)(object)val6) ? ((HorizontalOrVerticalLayoutGroup)val6).spacing : 8f);
				((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
				ContentSizeFitter obj2 = val3.AddComponent<ContentSizeFitter>();
				obj2.horizontalFit = (FitMode)0;
				obj2.verticalFit = (FitMode)2;
				AddText(controller.eclipseDifficultyName, val3.transform, "KarmaHeading", "KARMACLIMB_MENU_KARMA_HEADING", sizeToText: false);
				AddBadgeRow(val3.transform, componentInChildren);
				AddText(controller.eclipseDifficultyDescription, val3.transform, "KarmaHint", "KARMACLIMB_MENU_KARMA_HINT", sizeToText: true);
				KarmaPanelPlacer karmaPanelPlacer = val3.AddComponent<KarmaPanelPlacer>();
				karmaPanelPlacer.anchor = val2;
				karmaPanelPlacer.gap = 32f;
				Log.Info("Built the Karma box in the Eclipse menu's left column.");
			}
		}

		private static void CopyBackdrop(Transform rightPanel, GameObject panel)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)rightPanel))
			{
				return;
			}
			Image component = ((Component)rightPanel).GetComponent<Image>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Image obj = panel.AddComponent<Image>();
				obj.sprite = component.sprite;
				obj.type = component.type;
				((Graphic)obj).color = ((Graphic)component).color;
				((Graphic)obj).material = ((Graphic)component).material;
				obj.pixelsPerUnitMultiplier = component.pixelsPerUnitMultiplier;
				((Graphic)obj).raycastTarget = false;
			}
			string[] array = new string[2] { "BlurPanel", "BorderImage" };
			foreach (string text in array)
			{
				Transform val = rightPanel.Find(text);
				if (Object.op_Implicit((Object)(object)val))
				{
					GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, panel.transform);
					((Object)val2).name = text;
					RectTransform val3 = (RectTransform)val2.transform;
					val3.anchorMin = Vector2.zero;
					val3.anchorMax = Vector2.one;
					val3.offsetMin = Vector2.zero;
					val3.offsetMax = Vector2.zero;
					LayoutElement val4 = val2.GetComponent<LayoutElement>();
					if (!Object.op_Implicit((Object)(object)val4))
					{
						val4 = val2.AddComponent<LayoutElement>();
					}
					val4.ignoreLayout = true;
				}
			}
		}

		private static LanguageTextMeshController AddText(LanguageTextMeshController template, Transform parent, string name, string token, bool sizeToText)
		{
			if (!Object.op_Implicit((Object)(object)template))
			{
				Log.Warning("No text template for " + name + "; it will be missing from the Karma box.");
				return null;
			}
			LanguageTextMeshController val = Object.Instantiate<LanguageTextMeshController>(template, parent);
			((Object)((Component)val).gameObject).name = name;
			val.token = token;
			if (sizeToText)
			{
				LayoutElement[] components = ((Component)val).GetComponents<LayoutElement>();
				foreach (LayoutElement obj in components)
				{
					obj.minHeight = -1f;
					obj.preferredHeight = -1f;
					obj.flexibleHeight = -1f;
				}
			}
			return val;
		}

		private static void AddBadgeRow(Transform parent, EclipseDifficultyMedalDisplay medalTemplate)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("KarmaBadgeRow", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 6f;
			RectTransform component = ((Component)medalTemplate).GetComponent<RectTransform>();
			float num;
			if (Object.op_Implicit((Object)(object)component))
			{
				Rect rect = component.rect;
				if (((Rect)(ref rect)).height > 0f)
				{
					rect = component.rect;
					num = ((Rect)(ref rect)).height;
					goto IL_0097;
				}
			}
			num = 64f;
			goto IL_0097;
			IL_0097:
			float num2 = num;
			LayoutElement obj2 = val.AddComponent<LayoutElement>();
			obj2.minHeight = num2;
			obj2.preferredHeight = num2;
			for (int i = 1; i <= 8; i++)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)medalTemplate).gameObject, val.transform);
				((Object)val2).name = $"KarmaBadge{i}";
				val2.SetActive(true);
				EclipseDifficultyMedalDisplay component2 = val2.GetComponent<EclipseDifficultyMedalDisplay>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					((Behaviour)component2).enabled = false;
					Object.Destroy((Object)(object)component2);
				}
				Image component3 = val2.GetComponent<Image>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					Sprite val3 = FindKarmaSprite(i);
					if (Object.op_Implicit((Object)(object)val3))
					{
						component3.sprite = val3;
					}
					((Graphic)component3).color = Color.white;
					((Graphic)component3).raycastTarget = true;
				}
				TooltipProvider val4 = val2.GetComponent<TooltipProvider>();
				if (!Object.op_Implicit((Object)(object)val4))
				{
					val4 = val2.AddComponent<TooltipProvider>();
				}
				val4.titleToken = KarmaDescriptions.TitleToken(i);
				val4.titleColor = Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)12));
				val4.bodyToken = KarmaDescriptions.BodyToken(i);
			}
		}

		private static Sprite FindKarmaSprite(int karmaLevel)
		{
			RuleChoiceDef val = RuleCatalog.FindChoiceDef("Karma.InitialLevel." + karmaLevel);
			if (val == null)
			{
				Log.Warning($"No Karma.InitialLevel.{karmaLevel} rule choice; the badge keeps the medal artwork.");
				return null;
			}
			return val.sprite;
		}
	}
	internal static class EclipseMenuLayout
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Awake <>9__1_0;

			internal void <Init>b__1_0(orig_Awake orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				Apply(self);
			}
		}

		private static float extraWidth;

		internal static void Init(float rightPanelExtraWidth)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			extraWidth = rightPanelExtraWidth;
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				hook_Awake val = delegate(orig_Awake orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					Apply(self);
				};
				<>c.<>9__1_0 = val;
				obj = (object)val;
			}
			EclipseRunScreenController.Awake += (hook_Awake)obj;
		}

		private static void Apply(EclipseRunScreenController controller)
		{
			Widen(controller);
			FreeHeights(controller);
		}

		private static void Widen(EclipseRunScreenController controller)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (extraWidth <= 0f)
			{
				return;
			}
			Transform val = ((Component)controller).transform.Find("Main Panel/RightPanel");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Warning("No 'Main Panel/RightPanel'; leaving the Eclipse menu width alone.");
				return;
			}
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Vector2 sizeDelta = component.sizeDelta;
				sizeDelta.x += extraWidth;
				component.sizeDelta = sizeDelta;
				Vector2 anchoredPosition = component.anchoredPosition;
				anchoredPosition.x -= (1f - component.pivot.x) * extraWidth;
				component.anchoredPosition = anchoredPosition;
				Log.Debug($"Widened the Eclipse right panel by {extraWidth}.");
			}
		}

		private static void FreeHeights(EclipseRunScreenController controller)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			LanguageTextMeshController eclipseDifficultyDescription = controller.eclipseDifficultyDescription;
			if (!Object.op_Implicit((Object)(object)eclipseDifficultyDescription))
			{
				return;
			}
			Release(((Component)eclipseDifficultyDescription).GetComponent<LayoutElement>());
			Transform parent = ((Component)eclipseDifficultyDescription).transform.parent;
			Transform val = ((Component)controller).transform.Find("Main Panel/RightPanel");
			if (Object.op_Implicit((Object)(object)parent))
			{
				Release(((Component)parent).GetComponent<LayoutElement>());
				SizeToChildren(((Component)parent).GetComponent<VerticalLayoutGroup>());
				ContentSizeFitter component = ((Component)parent).GetComponent<ContentSizeFitter>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Object.Destroy((Object)(object)component);
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			foreach (Transform item in val)
			{
				Transform val2 = item;
				if (!((Object)val2).name.Contains("Border") && !((Object)val2).name.Contains("Blur"))
				{
					Release(((Component)val2).GetComponent<LayoutElement>());
					SizeToChildren(((Component)val2).GetComponent<VerticalLayoutGroup>());
				}
			}
			VerticalLayoutGroup component2 = ((Component)val).GetComponent<VerticalLayoutGroup>();
			SizeToChildren(component2);
			if (Object.op_Implicit((Object)(object)component2))
			{
				((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true;
			}
			PinTopEdge((RectTransform)(object)((val is RectTransform) ? val : null));
			ContentSizeFitter val3 = ((Component)val).GetComponent<ContentSizeFitter>();
			if (!Object.op_Implicit((Object)(object)val3))
			{
				val3 = ((Component)val).gameObject.AddComponent<ContentSizeFitter>();
			}
			val3.horizontalFit = (FitMode)0;
			val3.verticalFit = (FitMode)2;
		}

		private static void PinTopEdge(RectTransform rect)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)rect) && !Mathf.Approximately(rect.pivot.y, 1f))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				rect.GetWorldCorners(array);
				float y = array[1].y;
				rect.pivot = new Vector2(rect.pivot.x, 1f);
				rect.GetWorldCorners(array);
				((Transform)rect).position = ((Transform)rect).position + new Vector3(0f, y - array[1].y, 0f);
			}
		}

		private static void SizeToChildren(VerticalLayoutGroup layout)
		{
			if (Object.op_Implicit((Object)(object)layout))
			{
				((HorizontalOrVerticalLayoutGroup)layout).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)layout).childForceExpandHeight = false;
			}
		}

		private static void Release(LayoutElement layoutElement)
		{
			if (Object.op_Implicit((Object)(object)layoutElement))
			{
				layoutElement.preferredHeight = -1f;
				layoutElement.minHeight = -1f;
				layoutElement.flexibleHeight = -1f;
			}
		}
	}
	internal static class EclipseMenuMedals
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_Awake <>9__0_0;

			public static hook_UpdateDisplayedSurvivor <>9__0_1;

			internal void <Init>b__0_0(orig_Awake orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				AddMedals(self);
			}

			internal void <Init>b__0_1(orig_UpdateDisplayedSurvivor orig, EclipseRunScreenController self)
			{
				orig.Invoke(self);
				RefreshAll(self);
			}
		}

		internal static void Init()
		{
			//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)
			//IL_001f: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				hook_Awake val = delegate(orig_Awake orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					AddMedals(self);
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			EclipseRunScreenController.Awake += (hook_Awake)obj;
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				hook_UpdateDisplayedSurvivor val2 = delegate(orig_UpdateDisplayedSurvivor orig, EclipseRunScreenController self)
				{
					orig.Invoke(self);
					RefreshAll(self);
				};
				<>c.<>9__0_1 = val2;
				obj2 = (object)val2;
			}
			EclipseRunScreenController.UpdateDisplayedSurvivor += (hook_UpdateDisplayedSurvivor)obj2;
		}

		private static void RefreshAll(EclipseRunScreenController controller)
		{
			EclipseDifficultyMedalDisplay[] componentsInChildren = ((Component)controller).GetComponentsInChildren<EclipseDifficultyMedalDisplay>(true);
			foreach (EclipseDifficultyMedalDisplay val in componentsInChildren)
			{
				Transform parent = ((Component)val).transform.parent;
				if (!Object.op_Implicit((Object)(object)parent) || !(((Object)parent).name == "KarmaBadgeRow"))
				{
					val.Refresh();
				}
			}
		}

		private static void AddMedals(EclipseRunScreenController controller)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			EclipseDifficultyMedalDisplay val = null;
			EclipseDifficultyMedalDisplay[] componentsInChildren = ((Component)controller).GetComponentsInChildren<EclipseDifficultyMedalDisplay>(true);
			foreach (EclipseDifficultyMedalDisplay val2 in componentsInChildren)
			{
				if (val2.eclipseLevel > 8)
				{
					return;
				}
				if (!Object.op_Implicit((Object)(object)val) || val2.eclipseLevel > val.eclipseLevel)
				{
					val = val2;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Log.Warning("Eclipse menu has no medal displays; levels 9-16 will have no medals.");
				return;
			}
			Transform val3 = CreateSecondRow(((Component)val).transform.parent);
			int num = 0;
			for (int j = 9; j <= 16; j++)
			{
				Sprite val4 = KarmaClimbMedalArt.Active(j);
				Sprite val5 = KarmaClimbMedalArt.Inactive(j);
				if (!Object.op_Implicit((Object)(object)val4) || !Object.op_Implicit((Object)(object)val5))
				{
					Log.Warning($"Missing medal art for Eclipse {j}; skipping its medal.");
					continue;
				}
				GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, val3);
				((Object)obj).name = $"KarmaClimbMedal{j}";
				EclipseDifficultyMedalDisplay component = obj.GetComponent<EclipseDifficultyMedalDisplay>();
				component.eclipseLevel = j;
				component.unearnedSprite = val5;
				component.incompleteSprite = val4;
				component.completeSprite = val4;
				if (Object.op_Implicit((Object)(object)component.iconImage))
				{
					((Graphic)component.iconImage).color = Color.white;
				}
				num++;
			}
			Log.Info($"Added {num} Eclipse medals to the menu (levels {9}-{16}).");
		}

		private static Transform CreateSecondRow(Transform vanillaRow)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("KarmaClimbMedalRow", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(vanillaRow.parent, false);
			val.transform.SetSiblingIndex(vanillaRow.GetSiblingIndex() + 1);
			HorizontalLayoutGroup component = ((Component)vanillaRow).GetComponent<HorizontalLayoutGroup>();
			HorizontalLayoutGroup val2 = val.AddComponent<HorizontalLayoutGroup>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((LayoutGroup)val2).padding = ((LayoutGroup)component).padding;
				((HorizontalOrVerticalLayoutGroup)val2).spacing = ((HorizontalOrVerticalLayoutGroup)component).spacing;
				((LayoutGroup)val2).childAlignment = ((LayoutGroup)component).childAlignment;
				((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = ((HorizontalOrVerticalLayoutGroup)component).childControlWidth;
				((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = ((HorizontalOrVerticalLayoutGroup)component).childControlHeight;
				((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth;
				((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = ((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight;
				((HorizontalOrVerticalLayoutGroup)val2).childScaleWidth = ((HorizontalOrVerticalLayoutGroup)component).childScaleWidth;
				((HorizontalOrVerticalLayoutGroup)val2).childScaleHeight = ((HorizontalOrVerticalLayoutGroup)component).childScaleHeight;
				((HorizontalOrVerticalLayoutGroup)val2).reverseArrangement = ((HorizontalOrVerticalLayoutGroup)component).reverseArrangement;
			}
			return val.transform;
		}
	}
	internal static class KarmaClimbDifficulties
	{
		private static readonly Dictionary<int, DifficultyIndex> LevelToIndex = new Dictionary<int, DifficultyIndex>();

		private static readonly Dictionary<DifficultyIndex, int> IndexToLevel = new Dictionary<DifficultyIndex, int>();

		internal static IEnumerable<KeyValuePair<int, DifficultyIndex>> RegisteredLevels => LevelToIndex;

		internal static void Register()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected I4, but got Unknown
			for (int i = 9; i <= 16; i++)
			{
				DifficultyDef val = new DifficultyDef(3f, KarmaClimbLadder.NameToken(i), "Textures/DifficultyIcons/texDifficultyEclipse8Icon", KarmaClimbLadder.DescriptionToken(i), Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)17)), "mn", true);
				Sprite val2 = KarmaClimbMedalArt.Active(i);
				if (Object.op_Implicit((Object)(object)val2))
				{
					val.iconSprite = val2;
					val.foundIconSprite = true;
				}
				DifficultyIndex val3 = DifficultyAPI.AddDifficulty(val, true, true);
				if ((int)val3 == -1)
				{
					Log.Error($"R2API refused the difficulty for Eclipse {i}; the ladder will stop at {i - 1}.");
					break;
				}
				LevelToIndex[i] = val3;
				IndexToLevel[val3] = i;
				Log.Debug($"Eclipse {i} registered as DifficultyIndex {(int)val3} (Karma {KarmaClimbLadder.KarmaLevelFor(i)}).");
			}
		}

		internal static bool TryGetDifficultyIndex(int eclipseLevel, out DifficultyIndex index)
		{
			return LevelToIndex.TryGetValue(eclipseLevel, out index);
		}

		internal static bool TryGetEclipseLevel(DifficultyIndex index, out int eclipseLevel)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return IndexToLevel.TryGetValue(index, out eclipseLevel);
		}
	}
	internal static class KarmaClimbLadder
	{
		internal const int VanillaMaxLevel = 8;

		internal const int MaxLevel = 16;

		internal const int AddedLevelCount = 8;

		internal static bool IsKarmaClimbLevel(int eclipseLevel)
		{
			if (eclipseLevel > 8)
			{
				return eclipseLevel <= 16;
			}
			return false;
		}

		internal static int KarmaLevelFor(int eclipseLevel)
		{
			if (!IsKarmaClimbLevel(eclipseLevel))
			{
				return 0;
			}
			return eclipseLevel - 8;
		}

		internal static string NameToken(int eclipseLevel)
		{
			return $"KARMACLIMB_ECLIPSE_{eclipseLevel}_NAME";
		}

		internal static string DescriptionToken(int eclipseLevel)
		{
			return $"KARMACLIMB_ECLIPSE_{eclipseLevel}_DESCRIPTION";
		}

		internal static string UnlockableName(string survivorCachedName, int eclipseLevel)
		{
			return $"Eclipse.{survivorCachedName}.{eclipseLevel}";
		}

		internal static string UnlockableNameToken(int eclipseLevel)
		{
			return $"KARMACLIMB_UNLOCKABLE_ECLIPSE_{eclipseLevel}_NAME";
		}
	}
	internal static class KarmaClimbLanguage
	{
		private static readonly string[] InheritedEffects = new string[8] { "Ally Starting Health: <style=cIsHealth>-50%</style>", "Teleporter Radius: <style=cIsHealth>-50%</style>", "Ally Fall Damage: <style=cIsHealth>+100% and lethal</style>", "Enemy Speed: <style=cIsHealth>+40%</style>", "Ally Healing: <style=cIsHealth>-50%</style>", "Enemy Gold Drops: <style=cIsHealth>-20%</style>", "Enemy Cooldowns: <style=cIsHealth>-50%</style>", "Allies recieve <style=cIsHealth>permanent damage</style>" };

		internal static void Register()
		{
			LanguageAPI.Add("ECLIPSE_GAMEMODE_DESCRIPTION", "<style=cIsUtility>Eclipse</style> is a gamemode that adds stacking challenge modifiers to your run.\n\nEach time you <style=cIsUtility>beat the game</style>, your Eclipse level <style=cIsUtility>permanently increases</style> " + $"with that Survivor, up to a maximum of <style=cIsUtility>{16}</style> times.\n\n" + $"Levels <style=cIsUtility>{9}-{16}</style> keep every " + $"Eclipse {8} modifier and add <style=cIsUtility>Karma</style>, " + "which stays <style=cIsUtility>locked at its starting level</style> for the whole run.");
			for (int i = 9; i <= 16; i++)
			{
				int karma = KarmaClimbLadder.KarmaLevelFor(i);
				LanguageAPI.Add(KarmaClimbLadder.NameToken(i), $"Eclipse ({i})");
				LanguageAPI.Add(KarmaClimbLadder.DescriptionToken(i), BuildDescription(i, karma));
				LanguageAPI.Add(KarmaClimbLadder.UnlockableNameToken(i), $"Eclipse ({i})");
			}
		}

		private static string BuildDescription(int level, int karma)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("Starts at baseline Monsoon difficulty. <style=cSub>\n");
			for (int i = 0; i < InheritedEffects.Length; i++)
			{
				stringBuilder.Append("\n<mspace=0.5em>(").Append(i + 1).Append(")</mspace> ")
					.Append(InheritedEffects[i])
					.Append(' ');
			}
			stringBuilder.Append("\n<mspace=0.5em>(").Append(level).Append(")</mspace> Karma: <style=cIsHealth>locked at ")
				.Append(karma)
				.Append("</style></style>");
			return stringBuilder.ToString();
		}
	}
	internal static class KarmaClimbMedalArt
	{
		private static readonly Dictionary<string, Sprite> Cache = new Dictionary<string, Sprite>();

		internal static Sprite Active(int eclipseLevel)
		{
			return Load($"texKarmaClimbMedal{eclipseLevel}Active");
		}

		internal static Sprite Inactive(int eclipseLevel)
		{
			return Load($"texKarmaClimbMedal{eclipseLevel}Inactive");
		}

		private static Sprite Load(string name)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.TryGetValue(name, out var value))
			{
				return value;
			}
			Sprite val = null;
			string text = "KarmaClimb.Medals." + name + ".png";
			using (Stream stream = typeof(KarmaClimbMedalArt).Assembly.GetManifestResourceStream(text))
			{
				if (stream == null)
				{
					Log.Error("Missing embedded medal art " + text + ".");
				}
				else
				{
					using MemoryStream memoryStream = new MemoryStream();
					stream.CopyTo(memoryStream);
					Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false)
					{
						name = name,
						wrapMode = (TextureWrapMode)1,
						filterMode = (FilterMode)1
					};
					if (ImageConversion.LoadImage(val2, memoryStream.ToArray()))
					{
						val = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
						((Object)val).name = name;
					}
					else
					{
						Log.Error("Could not decode embedded medal art " + text + ".");
					}
				}
			}
			Cache[name] = val;
			return val;
		}
	}
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("chen-ror2.KarmaClimb", "KarmaClimb", "1.0.0")]
	public class KarmaClimbPlugin : BaseUnityPlugin
	{
		public const string PluginAuthor = "chen-ror2";

		public const string PluginName = "KarmaClimb";

		public const string PluginGuid = "chen-ror2.KarmaClimb";

		public const string PluginVersion = "1.0.0";

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			KarmaClimbLanguage.Register();
			KarmaDescriptions.Register();
			KarmaClimbDifficulties.Register();
			KarmaClimbUnlockables.Init();
			EclipseLadderHooks.Init();
			EclipseKarmaLock.Init();
			EclipseMenuMedals.Init();
			EclipseMenuKarmaPanel.Init();
			EclipseMenuLayout.Init(((BaseUnityPlugin)this).Config.Bind<float>("Eclipse menu", "RightPanelExtraWidth", 260f, "Pixels to widen the Eclipse menu's right-hand column by, growing leftwards. 0 disables.").Value);
			EclipseMenuEscape.Init();
			EclipseMenuDump.Init(((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogEclipseMenuHierarchy", false, "Logs the Eclipse menu's transform tree once, to position the Karma section against the real hierarchy. Turn off when the layout is settled.").Value);
			Log.Info(string.Format("{0} {1} ready: Eclipse now climbs to {2}.", "KarmaClimb", "1.0.0", 16));
		}
	}
	internal static class KarmaClimbUnlockables
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_SetUnlockableDefs <>9__0_0;

			internal void <Init>b__0_0(orig_SetUnlockableDefs orig, UnlockableDef[] unlockableDefs)
			{
				orig.Invoke(Append(unlockableDefs));
			}
		}

		internal static void Init()
		{
			//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)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				hook_SetUnlockableDefs val = delegate(orig_SetUnlockableDefs orig, UnlockableDef[] unlockableDefs)
				{
					orig.Invoke(Append(unlockableDefs));
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			UnlockableCatalog.SetUnlockableDefs += (hook_SetUnlockableDefs)obj;
		}

		private static UnlockableDef[] Append(UnlockableDef[] vanillaDefs)
		{
			string text = "." + 8;
			Dictionary<string, UnlockableDef> dictionary = new Dictionary<string, UnlockableDef>();
			foreach (UnlockableDef val in vanillaDefs)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string cachedName = val.cachedName;
					if (!string.IsNullOrEmpty(cachedName) && cachedName.StartsWith("Eclipse.") && cachedName.EndsWith(text))
					{
						string key = cachedName.Substring("Eclipse.".Length, cachedName.Length - "Eclipse.".Length - text.Length);
						dictionary[key] = val;
					}
				}
			}
			if (dictionary.Count == 0)
			{
				Log.Error("Found no vanilla Eclipse level-8 unlockables; levels 9-16 will be unreachable.");
				return vanillaDefs;
			}
			List<UnlockableDef> list = new List<UnlockableDef>(dictionary.Count * 8);
			foreach (KeyValuePair<string, UnlockableDef> item in dictionary)
			{
				for (int j = 9; j <= 16; j++)
				{
					UnlockableDef val2 = Object.Instantiate<UnlockableDef>(item.Value);
					val2.cachedName = KarmaClimbLadder.UnlockableName(item.Key, j);
					((Object)val2).name = val2.cachedName;
					val2.nameToken = KarmaClimbLadder.UnlockableNameToken(j);
					list.Add(val2);
				}
			}
			Log.Info($"Added {list.Count} Eclipse unlockables across {dictionary.Count} survivors (levels {9}-{16}).");
			return vanillaDefs.Concat(list).ToArray();
		}
	}
	internal static class KarmaDescriptions
	{
		internal const string HeadingToken = "KARMACLIMB_MENU_KARMA_HEADING";

		internal const string HintToken = "KARMACLIMB_MENU_KARMA_HINT";

		private static readonly string[] Bodies = new string[9] { null, "Mithrix gains a crystal cluster on his hammer, and one further crystal piece at each Karma level up to 7.\n\nIn phases 1, 3 and 4, once he has taken damage equal to <style=cIsDamage>10%</style> of his maximum health he gains a <style=cIsUtility>5 second shell</style> that reduces every hit he takes to 1 damage.", "<style=cIsUtility>Movement and attack speed +30%</style>.\n\nSky Leap drops four bombs at the cardinal points that detonate once he lands, each releasing a ring of shockwaves for <style=cIsDamage>400% damage</style> that <style=cIsUtility>Cripple</style>. A gravity well also forms above his landing point and pulls players in while he is airborne.\n\nHis dash leaves three crystal spikes dealing <style=cIsDamage>200% damage</style> and applying <style=cIsDamage>Lunar Ruin</style>.\n\nIn phase 2, the throne grants items to monsters on his team every <style=cIsUtility>25 seconds</style>.", "Hammer Smash adds crawling waves and a ring of crystal spikes.\n\nHammer Swing releases a fan of five crystal spike trails.\n\nNeedle Barrage and Needle Burst travel faster and leave <style=cIsDamage>Lunar Ruin</style> spikes where they strike terrain.\n\nIn phase 2, monsters that die erupt into lines of flame.", "His subtitle becomes <style=cIsUtility>Apocalypse Aspirant</style>.\n\nHis Sky Leap landing calls down a meteor storm that damages every character in the arena.\n\nHis dash grants <style=cIsUtility>knockback immunity for 5 seconds</style>.\n\nIn phase 4, Lunar Orbs also send out spiralling crystal spike trails.", "<style=cIsDamage>Karmic Spires</style>: at the start of phases 1 and 3 he summons up to six spires roughly 75m away.\n\nIn phase 2, the throne periodically fires a blast at a player.", "<style=cIsUtility>Skill cooldowns halved</style>.\n\nAfter Big Spinny and Forbidden Pizza he resummons spires, up to six.\n\nIn phase 3, Shock Wave adds pairs of crawling waves that apply <style=cIsDamage>Lunar Ruin</style>, and his dash launches a homing bomb.\n\nMonsters from the director in phase 3 gain the <style=cIsDamage>Perfected</style> affix, and the <style=cIsDamage>Twisted</style> affix if Seekers of the Storm is enabled.\n\nIn phase 4, at 50% health or less, he gains a mortar volley, Lunar Chimera Golems and Lunar Chimera Wisps.", "No new mechanics at this level — only the cumulative damage increase.", "<style=cIsHealing>Maximum health +50%</style>.\n\nThe sky above the arena changes, and he uses different spawn lines, including separate lines when a player is the Heretic." };

		internal static string TitleToken(int karmaLevel)
		{
			return $"KARMACLIMB_KARMA_{karmaLevel}_TITLE";
		}

		internal static string BodyToken(int karmaLevel)
		{
			return $"KARMACLIMB_KARMA_{karmaLevel}_BODY";
		}

		internal static void Register()
		{
			LanguageAPI.Add("KARMACLIMB_MENU_KARMA_HEADING", "Karma");
			LanguageAPI.Add("KARMACLIMB_MENU_KARMA_HINT", "<style=cSub>Hover over a Karma level to see what it adds.</style>");
			for (int i = 1; i <= 8; i++)
			{
				LanguageAPI.Add(TitleToken(i), $"Karma {i}");
				LanguageAPI.Add(BodyToken(i), BuildBody(i));
			}
		}

		private static string BuildBody(int karmaLevel)
		{
			return $"<style=cSub>Cumulative: Mithrix damage <style=cIsDamage>+{karmaLevel}%</style>.</style>\n\n" + Bodies[karmaLevel];
		}
	}
	internal class KarmaPanelPlacer : MonoBehaviour
	{
		internal RectTransform anchor;

		internal float gap;

		private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

		private TMP_Text anchorText;

		private void Start()
		{
			anchorText = (Object.op_Implicit((Object)(object)anchor) ? ((Component)anchor).GetComponent<TMP_Text>() : null);
		}

		private void LateUpdate()
		{
			//IL_00bd: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)anchor))
			{
				return;
			}
			anchor.GetWorldCorners(corners);
			float x = corners[1].x;
			float num = corners[0].y;
			if (Object.op_Implicit((Object)(object)anchorText))
			{
				Bounds textBounds = anchorText.textBounds;
				if (((Bounds)(ref textBounds)).size.y > 0f)
				{
					float num2 = num;
					RectTransform obj = anchor;
					textBounds = anchorText.textBounds;
					num = Mathf.Min(num2, ((Transform)obj).TransformPoint(new Vector3(0f, ((Bounds)(ref textBounds)).min.y, 0f)).y);
				}
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(x, num - gap * ((Transform)anchor).lossyScale.y, ((Component)this).transform.position.z);
			Vector3 val2 = ((Component)this).transform.position - val;
			if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
			{
				((Component)this).transform.position = val;
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _source;

		internal static void Init(ManualLogSource source)
		{
			_source = source;
		}

		internal static void Debug(object data)
		{
			_source.LogDebug(data);
		}

		internal static void Info(object data)
		{
			_source.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_source.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_source.LogWarning(data);
		}

		internal static void Error(object data)
		{
			_source.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_source.LogFatal(data);
		}
	}
}