Decompiled source of CrestShuffler v1.0.2

CrestShuffler/CrestShuffler.dll

Decompiled 6 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
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("CrestShuffler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0+f2bd376b1267c561443171cb477e867a3ec47850")]
[assembly: AssemblyProduct("CrestShuffler")]
[assembly: AssemblyTitle("CrestShuffler")]
[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 CrestShuffler
{
	[BepInPlugin("com.cometcake575.crestshuffler", "Crest Shuffler", "1.0.2")]
	public class CrestShufflerPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass5_0
		{
			public HeroController hc;

			internal bool <RandomCrest>b__0()
			{
				return !hc.controlReqlinquished && !hc.cState.dashing && !hc.cState.airDashing;
			}
		}

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

			private object <>2__current;

			private <>c__DisplayClass5_0 <>8__1;

			private List<ToolCrest> <crests>5__2;

			private ToolCrest <crest>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>8__1 = null;
				<crests>5__2 = null;
				<crest>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass5_0();
					<>8__1.hc = HeroController.instance;
					<>2__current = (object)new WaitUntil((Func<bool>)(() => !<>8__1.hc.controlReqlinquished && !<>8__1.hc.cState.dashing && !<>8__1.hc.cState.airDashing));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<crests>5__2 = (from crest in ToolItemManager.GetAllCrests()
						where crest.name != PlayerData.instance.CurrentCrestID
						select crest).ToList();
					<crest>5__3 = <crests>5__2[Random.Range(0, <crests>5__2.Count)];
					PlayerData.instance.IsCurrentCrestTemp = true;
					ToolItemManager.AutoEquip(<crest>5__3, false);
					HeroController.instance.UpdateSilkCursed();
					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();
			}
		}

		internal static ManualLogSource Logger;

		private static int _rerollTime;

		private static float _timeUntilReroll;

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Crest Shuffler has loaded!");
			new Hook((MethodBase)typeof(InventoryToolCrest).GetProperty("IsHidden").GetGetMethod(), (Delegate)(Func<Func<InventoryToolCrest, bool>, InventoryToolCrest, bool>)((Func<InventoryToolCrest, bool> _, InventoryToolCrest _) => true));
			_rerollTime = ((BaseUnityPlugin)this).Config.Bind<int>("Options", "Reroll Time", 60, "How often the crest should be rerolled in seconds (-1 to disable the timer)").Value;
			_timeUntilReroll = _rerollTime;
			if (((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Reroll on transition", false, "Whether to reroll the crest when going through a scene transition").Value)
			{
				new Hook((MethodBase)typeof(HeroController).GetMethod("SceneInit"), (Delegate)(Action<Action<HeroController>, HeroController>)delegate(Action<HeroController> orig, HeroController self)
				{
					orig(self);
					((MonoBehaviour)this).StartCoroutine(RandomCrest());
				});
			}
			if (!((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Reroll on death", false, "Whether to reroll the crest when dying").Value)
			{
				return;
			}
			new Hook((MethodBase)typeof(HeroController).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (Delegate)(Action<Action<HeroController>, HeroController>)delegate(Action<HeroController> orig, HeroController self)
			{
				orig(self);
				self.OnDeath += delegate
				{
					((MonoBehaviour)this).StartCoroutine(RandomCrest());
				};
			});
		}

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)HeroController.instance) && _rerollTime > 0)
			{
				_timeUntilReroll -= Time.deltaTime;
				if (_timeUntilReroll <= 0f)
				{
					((MonoBehaviour)this).StartCoroutine(RandomCrest());
					_timeUntilReroll += _rerollTime;
				}
			}
		}

		[IteratorStateMachine(typeof(<RandomCrest>d__5))]
		private static IEnumerator RandomCrest()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RandomCrest>d__5(0);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrestShuffler";

		public const string PLUGIN_NAME = "CrestShuffler";

		public const string PLUGIN_VERSION = "1.0.0.0";
	}
}