Decompiled source of JustRetryForSure v1.6.7

JustRetryPlus.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JustRetryPlus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("JustRetryPlus")]
[assembly: AssemblyTitle("JustRetryPlus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 JustRetryPlus
{
	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	public static class ChangeLevelPatch
	{
		private static bool Prefix(RunManager __instance, ref bool _completedLevel, ref bool _levelFailed, ref ChangeLevelType _changeLevelType)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			if (!Plugin.IsEnabled)
			{
				return true;
			}
			Plugin.Logger.LogInfo((object)$"Level failed?: {_levelFailed}");
			Plugin.DidFailLevel = _levelFailed;
			if (Plugin.DidFailLevel)
			{
				if (Plugin.ShouldResetLevel)
				{
					Plugin.Logger.LogInfo((object)"Restarting at level one");
					__instance.ResetProgress();
					__instance.SetRunLevel();
				}
				else if (Plugin.ShouldHealAfterFail)
				{
					Plugin.Logger.LogInfo((object)"Preparing to heal after retry...");
					GameObject val = new GameObject("JustRetryPlus_HealRunner");
					Object.DontDestroyOnLoad((Object)(object)val);
					HealRunner healRunner = val.AddComponent<HealRunner>();
					((MonoBehaviour)healRunner).StartCoroutine(Plugin.HandleRestartHeal((MonoBehaviour)(object)healRunner));
				}
				Plugin.Logger.LogInfo((object)"Level failed, retrying...");
				__instance.RestartScene();
				Plugin.Logger.LogInfo((object)"Restarted scene");
				return false;
			}
			return true;
		}
	}
	public class HealRunner : MonoBehaviour
	{
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "JustRetryPlus";

		public const string PLUGIN_NAME = "JustRetryPlus";

		public const string PLUGIN_VERSION = "1.0.3";
	}
	[BepInPlugin("JustRetryPlus", "JustRetryPlus", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <HandleRestartHeal>d__20 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MonoBehaviour runner;

			private int <healAmount>5__1;

			private List<PlayerAvatar>.Enumerator <>s__2;

			private PlayerAvatar <player>5__3;

			private string <steamID>5__4;

			private int <maxHealth>5__5;

			private PhotonView <photonView>5__6;

			private List<string> <keys>5__7;

			private List<string>.Enumerator <>s__8;

			private string <key>5__9;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>s__2 = default(List<PlayerAvatar>.Enumerator);
				<player>5__3 = null;
				<steamID>5__4 = null;
				<photonView>5__6 = null;
				<keys>5__7 = null;
				<>s__8 = default(List<string>.Enumerator);
				<key>5__9 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Expected O, but got Unknown
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Expected O, but got Unknown
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_013d: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					goto IL_008a;
				case 2:
					<>1__state = -1;
					goto IL_008a;
				case 3:
					<>1__state = -1;
					goto IL_00cd;
				case 4:
					<>1__state = -1;
					goto IL_0102;
				case 5:
					{
						<>1__state = -1;
						<healAmount>5__1 = HealthToHealValue;
						<>s__2 = SemiFunc.PlayerGetAll().GetEnumerator();
						try
						{
							while (<>s__2.MoveNext())
							{
								<player>5__3 = <>s__2.Current;
								if ((Object)(object)<player>5__3 != (Object)null && (Object)(object)<player>5__3.playerHealth != (Object)null)
								{
									<steamID>5__4 = SemiFunc.PlayerGetSteamID(<player>5__3);
									if ((Object)(object)StatsManager.instance != (Object)null)
									{
										StatsManager.instance.SetPlayerHealth(<steamID>5__4, <healAmount>5__1, false);
									}
									<maxHealth>5__5 = (int)AccessTools.Field(typeof(PlayerHealth), "maxHealth").GetValue(<player>5__3.playerHealth);
									<healAmount>5__1 = Mathf.Clamp(<healAmount>5__1, 0, <maxHealth>5__5);
									AccessTools.Field(typeof(PlayerHealth), "health").SetValue(<player>5__3.playerHealth, <healAmount>5__1);
									<photonView>5__6 = ((Component)<player>5__3.playerHealth).GetComponent<PhotonView>();
									if ((Object)(object)<photonView>5__6 != (Object)null)
									{
										<photonView>5__6.RPC("UpdateHealthRPC", (RpcTarget)0, new object[4] { <healAmount>5__1, <maxHealth>5__5, true, false });
									}
									Logger.LogInfo((object)$"[JustRetryPlus] Successfully healed {<steamID>5__4} to {<healAmount>5__1} HP.");
									<steamID>5__4 = null;
									<photonView>5__6 = null;
								}
								<player>5__3 = null;
							}
						}
						finally
						{
							((IDisposable)<>s__2).Dispose();
						}
						<>s__2 = default(List<PlayerAvatar>.Enumerator);
						if ((Object)(object)StatsManager.instance != (Object)null)
						{
							if (StatsManager.instance.runStats.ContainsKey("chargingStationChargeTotal"))
							{
								StatsManager.instance.runStats["chargingStationCharge"] = StatsManager.instance.runStats["chargingStationChargeTotal"];
							}
							else
							{
								StatsManager.instance.runStats["chargingStationCharge"] = 100;
							}
							<keys>5__7 = new List<string>(StatsManager.instance.itemStatBattery.Keys);
							<>s__8 = <keys>5__7.GetEnumerator();
							try
							{
								while (<>s__8.MoveNext())
								{
									<key>5__9 = <>s__8.Current;
									StatsManager.instance.itemStatBattery[<key>5__9] = 100;
									<key>5__9 = null;
								}
							}
							finally
							{
								((IDisposable)<>s__8).Dispose();
							}
							<>s__8 = default(List<string>.Enumerator);
							<keys>5__7 = null;
						}
						if ((Object)(object)runner != (Object)null && (Object)(object)((Component)runner).gameObject != (Object)null)
						{
							Object.Destroy((Object)(object)((Component)runner).gameObject);
						}
						return false;
					}
					IL_00cd:
					if (!LevelGenerator.Instance.Generated)
					{
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 3;
						return true;
					}
					goto IL_0102;
					IL_008a:
					if ((Object)(object)GameDirector.instance == (Object)null || (Object)(object)LevelGenerator.Instance == (Object)null)
					{
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 2;
						return true;
					}
					goto IL_00cd;
					IL_0102:
					if (GameDirector.instance.PlayerList == null || GameDirector.instance.PlayerList.Count < PhotonNetwork.PlayerList.Length)
					{
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 4;
						return true;
					}
					<>2__current = (object)new WaitForSeconds(1.5f);
					<>1__state = 5;
					return true;
				}
			}

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

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

		internal static ManualLogSource Logger;

		private static ConfigEntry<bool> _shouldResetLevel;

		private static ConfigEntry<bool> _shouldHealAfterFail;

		private static ConfigEntry<bool> _isEnabled;

		private static ConfigEntry<int> _healthToHeal;

		public static Plugin Instance;

		public static bool ShouldResetLevel => _shouldResetLevel.Value;

		public static bool ShouldHealAfterFail => _shouldHealAfterFail.Value;

		public static bool DidFailLevel { get; set; }

		public static bool IsEnabled => _isEnabled.Value;

		public static int HealthToHealValue => _healthToHeal.Value;

		private void Awake()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin JustRetryPlus is loaded!");
			Logger.LogInfo((object)"Thanks for nickklmao for the original Idea and bits of code! please check out their mods on Thunderstore!");
			Logger.LogInfo((object)"Without them this mod wouldn't be possible!");
			Harmony val = new Harmony("eu.xaru.justretryplus");
			val.PatchAll();
			Logger.LogInfo((object)"Harmony patches applied.");
			_isEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "IsEnabled", true, new ConfigDescription("Toggle if the plugin should be enabled, if false the normal game death scene will take over", (AcceptableValueBase)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
			_shouldResetLevel = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "ShouldResetLevel", false, new ConfigDescription("Toggle if the game should restart at level one & reset the map when failing a level", (AcceptableValueBase)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
			_shouldHealAfterFail = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "ShouldHealAfterFail", true, new ConfigDescription("Toggle if the game should restart with full health when failing a level", (AcceptableValueBase)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
			_healthToHeal = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "HealthToHeal", 100, new ConfigDescription("The amount of health to heal when failing a level", (AcceptableValueBase)new AcceptableValueRange<int>(0, 500), Array.Empty<object>()));
		}

		private void Start()
		{
			Logger.LogInfo((object)"JustRetryPlus started!");
		}

		[IteratorStateMachine(typeof(<HandleRestartHeal>d__20))]
		public static IEnumerator HandleRestartHeal(MonoBehaviour runner)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HandleRestartHeal>d__20(0)
			{
				runner = runner
			};
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "JustRetryPlus";

		public const string PLUGIN_NAME = "JustRetryPlus";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}