Decompiled source of EndlessMode v2.0.0

EndlessMode.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using EndlessMode;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Endless Mode", "2.2.0", "Neptune6866", null)]
[assembly: MelonGame("Buried Things", "Cursed Words")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EndlessMode")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EndlessMode")]
[assembly: AssemblyTitle("EndlessMode")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 EndlessMode
{
	public class Core : MelonMod
	{
		public static bool EndlessRunActive;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).HarmonyInstance.PatchAll();
			MelonLogger.Msg("[Endless Mode] Loaded.");
		}
	}
	[HarmonyPatch(typeof(MainMenuOptionsController), "Start")]
	internal class Endless_AddButton
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__1_0;

			internal void <Setup>b__1_0()
			{
				Core.EndlessRunActive = true;
				MelonLogger.Msg((object)Core.EndlessRunActive);
			}
		}

		[CompilerGenerated]
		private sealed class <Setup>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MainMenuOptionsController instance;

			private BindingFlags <flags>5__1;

			private FieldInfo <newRunField>5__2;

			private GameObject <newRunButton>5__3;

			private Transform <mainContainer>5__4;

			private Transform <canvasRoot>5__5;

			private Transform <surveyAndWishlist>5__6;

			private Transform <topRight>5__7;

			private GameObject <endlessButton>5__8;

			private TextMeshProUGUI <tmp>5__9;

			private Button <button>5__10;

			private Transform <wishlist>5__11;

			private Transform <survey>5__12;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Setup>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<newRunField>5__2 = null;
				<newRunButton>5__3 = null;
				<mainContainer>5__4 = null;
				<canvasRoot>5__5 = null;
				<surveyAndWishlist>5__6 = null;
				<topRight>5__7 = null;
				<endlessButton>5__8 = null;
				<tmp>5__9 = null;
				<button>5__10 = null;
				<wishlist>5__11 = null;
				<survey>5__12 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01c0: 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)
				//IL_01cb: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					<flags>5__1 = BindingFlags.Instance | BindingFlags.NonPublic;
					<newRunField>5__2 = typeof(MainMenuOptionsController).GetField("_newRunGO", <flags>5__1);
					if (<newRunField>5__2 == null)
					{
						return false;
					}
					ref GameObject reference = ref <newRunButton>5__3;
					object? value = <newRunField>5__2.GetValue(instance);
					reference = (GameObject)((value is GameObject) ? value : null);
					if ((Object)(object)<newRunButton>5__3 == (Object)null)
					{
						return false;
					}
					<mainContainer>5__4 = <newRunButton>5__3.transform.parent;
					if ((Object)(object)<mainContainer>5__4 == (Object)null)
					{
						return false;
					}
					if ((Object)(object)GameObject.Find("EndlessRunButton") == (Object)null)
					{
						<endlessButton>5__8 = Object.Instantiate<GameObject>(<newRunButton>5__3, <mainContainer>5__4);
						((Object)<endlessButton>5__8).name = "EndlessRunButton";
						<endlessButton>5__8.transform.SetSiblingIndex(<newRunButton>5__3.transform.GetSiblingIndex() + 1);
						<tmp>5__9 = <endlessButton>5__8.GetComponentInChildren<TextMeshProUGUI>(true);
						if ((Object)(object)<tmp>5__9 != (Object)null)
						{
							((TMP_Text)<tmp>5__9).text = "ENDLESS MODE";
						}
						<button>5__10 = <endlessButton>5__8.GetComponentInChildren<Button>(true);
						if ((Object)(object)<button>5__10 == (Object)null)
						{
							MelonLogger.Error("No Button component found in Endless clone!");
							return false;
						}
						ButtonClickedEvent onClick = <button>5__10.onClick;
						object obj = <>c.<>9__1_0;
						if (obj == null)
						{
							UnityAction val = delegate
							{
								Core.EndlessRunActive = true;
								MelonLogger.Msg((object)Core.EndlessRunActive);
							};
							<>c.<>9__1_0 = val;
							obj = (object)val;
						}
						((UnityEvent)onClick).AddListener((UnityAction)obj);
						<endlessButton>5__8.SetActive(true);
						<endlessButton>5__8 = null;
						<tmp>5__9 = null;
						<button>5__10 = null;
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				case 2:
					<>1__state = -1;
					<canvasRoot>5__5 = <newRunButton>5__3.transform.root;
					if ((Object)(object)<canvasRoot>5__5 == (Object)null)
					{
						return false;
					}
					<surveyAndWishlist>5__6 = <canvasRoot>5__5.Find("OptionsLayoutParent/SurveyAndWishlist");
					<topRight>5__7 = <canvasRoot>5__5.Find("TopRightLayoutParent");
					if ((Object)(object)<surveyAndWishlist>5__6 != (Object)null && (Object)(object)<topRight>5__7 != (Object)null)
					{
						<wishlist>5__11 = <surveyAndWishlist>5__6.Find("WishlistParent");
						<survey>5__12 = <surveyAndWishlist>5__6.Find("SurveyParent");
						if ((Object)(object)<wishlist>5__11 != (Object)null)
						{
							<wishlist>5__11.SetParent(<topRight>5__7, false);
							<wishlist>5__11.SetAsLastSibling();
						}
						if ((Object)(object)<survey>5__12 != (Object)null)
						{
							<survey>5__12.SetParent(<topRight>5__7, false);
							<survey>5__12.SetAsLastSibling();
						}
						<wishlist>5__11 = null;
						<survey>5__12 = null;
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static void Postfix(MainMenuOptionsController __instance)
		{
			((MonoBehaviour)__instance).StartCoroutine(Setup(__instance));
		}

		[IteratorStateMachine(typeof(<Setup>d__1))]
		private static IEnumerator Setup(MainMenuOptionsController instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Setup>d__1(0)
			{
				instance = instance
			};
		}
	}
	[HarmonyPatch(typeof(RunProgress), "IsFinalStage")]
	internal class Endless_PreventFinalStage
	{
		private static void Postfix(ref bool __result)
		{
			if (Core.EndlessRunActive)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(RunProgress), "AdvanceToNextNodeType")]
	internal class Endless_FixStageShop
	{
		private static bool Prefix(RunProgress __instance, ref NodeType __result)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected I4, but got Unknown
			if (!Core.EndlessRunActive)
			{
				return true;
			}
			if ((int)__instance.CurrentNodeType == 5 && __instance.GetStage() >= 6)
			{
				__instance.CurrentStage++;
				__instance.CurrentNodeType = (NodeType)2;
				__result = (NodeType)(int)__instance.CurrentNodeType;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(RunProgress), "GetCurrentBossDraft")]
	internal class Endless_FreshBossDraft
	{
		private static bool Prefix(RunProgress __instance, ref BossDraft __result)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			if (!Core.EndlessRunActive)
			{
				return true;
			}
			if (__instance.GetStage() <= 6)
			{
				return true;
			}
			List<BossDraft> bossDrafts = __instance.BossDrafts;
			if (bossDrafts == null || bossDrafts.Count == 0)
			{
				return true;
			}
			BossDraft val = bossDrafts[0];
			if (val == null)
			{
				return true;
			}
			BossDraft val2 = new BossDraft();
			FieldInfo[] fields = typeof(BossDraft).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(val2, fieldInfo.GetValue(val));
			}
			List<BossModifier> list = new List<BossModifier>();
			foreach (BossDraft item in bossDrafts)
			{
				if (item.AvailableBosses != null)
				{
					list.AddRange(item.AvailableBosses);
				}
			}
			if (list.Count < 2)
			{
				return true;
			}
			BossModifier val3 = list[Random.Range(0, list.Count)];
			BossModifier val4;
			do
			{
				val4 = list[Random.Range(0, list.Count)];
			}
			while (val4 == val3);
			val2.AvailableBosses = new List<BossModifier> { val3, val4 };
			__result = val2;
			return false;
		}
	}
	[HarmonyPatch(typeof(RunProgress), "GetEncounterTarget")]
	internal class Endless_ControlledScaling
	{
		private static bool Prefix(int stage, NodeType nodeType, AscensionLevel ascension, ref ScorePacket __result)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if (!Core.EndlessRunActive)
			{
				return true;
			}
			double num = 15.0;
			double num2 = Math.Pow(2.6, stage - 1);
			double num3 = (((int)nodeType == 4) ? 1.4 : (((int)nodeType == 7) ? 2.0 : 1.0));
			double num4 = 1.0 + (double)ascension * 0.3;
			double val = num * num2 * num3 * num4;
			val = Math.Max(1.0, Math.Min(val, 9.223372036854776E+18));
			__result = new ScorePacket((long)Math.Round(val));
			return false;
		}
	}
	[HarmonyPatch(typeof(GameStatics), "GetMaxUpgradeCount")]
	internal class Endless_InfiniteUpgrades
	{
		private static bool Prefix(ref int __result)
		{
			if (!Core.EndlessRunActive)
			{
				return true;
			}
			__result = 999999;
			return false;
		}
	}
	[HarmonyPatch(typeof(SaveManager), "ClearCurrentRun")]
	internal class Endless_PreventRunClear
	{
		private static bool Prefix()
		{
			return !Core.EndlessRunActive;
		}
	}
	[HarmonyPatch(typeof(ScoreCalculation), "CalculateOverallScore")]
	internal class Endless_FoilWordBonus
	{
		private static void Postfix(List<ScoreCalcVizInfo> __result)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			if (!Core.EndlessRunActive)
			{
				return;
			}
			Player player = GameStatics.GetPlayer();
			if (player == null)
			{
				return;
			}
			int num = player.GetStickers().Count((Item i) => i.IsFoil);
			if (num > 0)
			{
				int num2 = __result.Count - 1;
				if (num2 >= 0)
				{
					ScoreCalcVizInfo val = __result[num2];
					val.WordBonus = new WordBonusToken(100 * num * 2, true, val.WordBonus?.IsPoison ?? false);
					val.IsPulsingWholeWord = true;
					__result[num2] = val;
				}
			}
		}
	}
	[HarmonyPatch(typeof(EndGameCanvasController), "Populate")]
	internal class Endless_ClampBossCount
	{
		private static void Prefix(RunStatistics stats)
		{
			if (Core.EndlessRunActive && stats?.Bosses != null && stats.Bosses.Count > 5)
			{
				stats.Bosses = stats.Bosses.Skip(stats.Bosses.Count - 5).ToList();
			}
		}
	}
	[HarmonyPatch(typeof(DialogueUtility), "GetStockFoilStickerQuip")]
	internal class Endless_FoilDialogueOverride
	{
		private static bool Prefix(Item item, bool secretSanta, ref (string, Emotions) __result)
		{
			if (!Core.EndlessRunActive)
			{
				return true;
			}
			List<(string, Emotions)> list = new List<(string, Emotions)>();
			list.Add(("A foil " + DialogueUtility.WobbleMarker + item.Name.ToUpper() + DialogueUtility.WobbleMarker + "! That will give you an extra Multiplier!", (Emotions)8));
			list.Add(("That Foil " + DialogueUtility.WobbleMarker + item.Name.ToUpper() + DialogueUtility.WobbleMarker + " will give you an extra Multiplier!", (Emotions)9));
			List<(string, Emotions)> list2 = list;
			__result = list2[Random.Range(0, list2.Count)];
			return false;
		}
	}
}