Decompiled source of TeleporterExpandOnBossKill v1.0.1

RoR2Tweaks.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using RoR2;
using RoR2Tweaks.Tweaks.Holdouts;
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("RoR2Tweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RoR2Tweaks")]
[assembly: AssemblyTitle("RoR2Tweaks")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RoR2Tweaks
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("bweh.RoR2Tweaks", "RoR2Tweaks", "1.0.0")]
	public class TeleExpansion : BaseUnityPlugin
	{
		private void Awake()
		{
			new TeleExpandOnBossKill();
		}
	}
}
namespace RoR2Tweaks.Tweaks.Holdouts
{
	public class TeleExpandOnBossKill
	{
		private sealed class ExpansionProgress
		{
			public float startTime;

			public float startRadius;
		}

		public static bool enabled = true;

		public static bool enableDuringEclipseUserFlag = false;

		private const float ExpansionDuration = 30f;

		private const float ExpansionMultiplier = 8f;

		private static readonly FieldInfo MonstersClearedField = typeof(TeleporterInteraction).GetField("monstersCleared", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly ConditionalWeakTable<HoldoutZoneController, ExpansionProgress> ExpansionByHoldout = new ConditionalWeakTable<HoldoutZoneController, ExpansionProgress>();

		public TeleExpandOnBossKill()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (enabled)
			{
				TeleporterInteraction.UpdateMonstersClear += new hook_UpdateMonstersClear(OnUpdateMonstersClear);
				HoldoutZoneController.DoUpdate += new Manipulator(HoldoutZoneController_DoUpdate);
			}
		}

		private static void OnUpdateMonstersClear(orig_UpdateMonstersClear orig, TeleporterInteraction self)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)self) && !(MonstersClearedField == null) && !((Object)(object)self.holdoutZoneController == (Object)null) && (bool)MonstersClearedField.GetValue(self) && (int)self.activationState == 2 && !(self.chargeFraction <= 0.05f) && Object.op_Implicit((Object)(object)Run.instance))
			{
				bool flag = (int)Run.instance.selectedDifficulty < 4;
				if ((enableDuringEclipseUserFlag || flag) && Util.GetItemCountForTeam(self.holdoutZoneController.chargingTeam, Items.FocusConvergence.itemIndex, true, true) <= 0 && !ExpansionByHoldout.TryGetValue(self.holdoutZoneController, out var _))
				{
					float currentRadius = self.holdoutZoneController.currentRadius;
					ExpansionByHoldout.Add(self.holdoutZoneController, new ExpansionProgress
					{
						startTime = Time.time,
						startRadius = Mathf.Max(currentRadius, 0.01f)
					});
				}
			}
		}

		private static void HoldoutZoneController_DoUpdate(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 3)
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<float, HoldoutZoneController, float>>((Func<float, HoldoutZoneController, float>)ApplyExpansion);
			}
			else
			{
				Debug.LogError((object)"TeleExpandOnBossKill: Failed to find HoldoutZoneController radius local.");
			}
		}

		private static float ApplyExpansion(float radius, HoldoutZoneController self)
		{
			if (!ExpansionByHoldout.TryGetValue(self, out var value))
			{
				return radius;
			}
			float num = Mathf.Clamp01((Time.time - value.startTime) / 30f);
			float num2 = Mathf.Max(value.startRadius, 0.01f);
			float num3 = num2 * 8f;
			return Mathf.Exp(Mathf.Lerp(Mathf.Log(num2), Mathf.Log(num3), num));
		}
	}
}