Decompiled source of CrestShuffler v1.2.1

CrestShuffler/CrestShuffler.dll

Decompiled a month 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 GlobalEnums;
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.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+2cbc356f143eb9c23f11286eeeb18b02e357478c")]
[assembly: AssemblyProduct("CrestShuffler")]
[assembly: AssemblyTitle("CrestShuffler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.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 CrestShuffler
{
	[BepInPlugin("com.cometcake575.crestshuffler", "Crest Shuffler", "1.2.1")]
	public class CrestShufflerPlugin : BaseUnityPlugin
	{
		private enum ToolMode
		{
			Off,
			Unlocked,
			All
		}

		internal static ManualLogSource Logger;

		private static int _rerollTime;

		private static float _timeUntilReroll;

		private static ToolMode _toolShuffle;

		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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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 damage", false, "Whether to reroll the crest when taking damage").Value)
			{
				new Hook((MethodBase)typeof(HeroController).GetMethod("TakeDamage"), (Delegate)(Action<Action<HeroController, GameObject, CollisionSide, int, HazardType, DamagePropertyFlags>, HeroController, GameObject, CollisionSide, int, HazardType, DamagePropertyFlags>)delegate(Action<HeroController, GameObject, CollisionSide, int, HazardType, DamagePropertyFlags> orig, HeroController self, GameObject go, CollisionSide damageSide, int damageAmount, HazardType hazardType, DamagePropertyFlags damagePropertyFlags)
				{
					//IL_001a: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: 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)
					if (self.CanTakeDamage())
					{
						((MonoBehaviour)this).StartCoroutine(RandomCrest());
					}
					orig(self, go, damageSide, damageAmount, hazardType, damagePropertyFlags);
				});
			}
			if (((BaseUnityPlugin)this).Config.Bind<bool>("Options", "Reroll on death", false, "Whether to reroll the crest when dying").Value)
			{
				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());
					};
				});
			}
			_toolShuffle = ((BaseUnityPlugin)this).Config.Bind<ToolMode>("Options", "Shuffle Tools", ToolMode.Off, "Whether to shuffle tools as well as the crest.\n'Unlocked' will give the player random tools they have unlocked.\n'All' will give the player random tools, including ones they do not have.").Value;
		}

		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;
				}
			}
		}

		private static IEnumerator RandomCrest()
		{
			yield return (object)new WaitForSeconds(0.05f);
			HeroController hc = HeroController.instance;
			yield return (object)new WaitUntil((Func<bool>)(() => !hc.controlReqlinquished && !hc.cState.dashing && !hc.cState.downAttacking && !hc.cState.downSpikeAntic && !hc.cState.airDashing && (int)HeroController.instance.transitionState == 0));
			List<ToolCrest> crests = (from val in ToolItemManager.GetAllCrests()
				where val.name != PlayerData.instance.CurrentCrestID
				select val).ToList();
			ToolCrest crest = crests[Random.Range(0, crests.Count)];
			PlayerData.instance.IsCurrentCrestTemp = true;
			ToolItemManager.AutoEquip(crest, false, false);
			HeroController.instance.UpdateSilkCursed();
			if (_toolShuffle != ToolMode.Off)
			{
				List<ToolItem> tools = ((_toolShuffle == ToolMode.Unlocked) ? ToolItemManager.GetUnlockedTools() : ToolItemManager.GetAllTools()).ToList();
				for (int i = 0; i < 30; i++)
				{
					ToolItemManager.AutoEquip(tools[Random.Range(0, tools.Count)]);
				}
			}
			yield return null;
			hc.RegainControl();
			hc.StartAnimationControl();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CrestShuffler";

		public const string PLUGIN_NAME = "CrestShuffler";

		public const string PLUGIN_VERSION = "1.2.1";
	}
}