Decompiled source of TeleExpansion v1.1.2

TeleExpansion.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using On.RoR2;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("TeleExpansion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TeleExpansion")]
[assembly: AssemblyTitle("TeleExpansion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TeleExpansion
{
	[BepInPlugin("com.Moffein.TeleExpansion", "Tele Expansion", "1.1.2")]
	public class TeleExpansion : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_UpdateMonstersClear <>9__6_0;

			internal void <Awake>b__6_0(orig_UpdateMonstersClear orig, TeleporterInteraction self)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Invalid comparison between Unknown and I4
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self);
				if (self.monstersCleared && Object.op_Implicit((Object)(object)self.holdoutZoneController) && (int)self.activationState == 2 && self.chargeFraction > 0.05f && Util.GetItemCountForTeam(self.holdoutZoneController.chargingTeam, Items.FocusConvergence.itemIndex, true, true) <= 0)
				{
					self.holdoutZoneController.currentRadius = 1000000f;
				}
			}
		}

		public static bool enableExpand = true;

		public static float teleRadiusMult = 1f;

		public static float teleDurationMult = 1f;

		public static float smallHoldoutRadiusMult = 1f;

		public static float smallHoldoutDurationMult = 1f;

		public void ReadConfig()
		{
			enableExpand = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Expansion", true, "Teleporter radius expands to cover the whole map when the boss dies.").Value;
			teleRadiusMult = ((BaseUnityPlugin)this).Config.Bind<float>("Teleporter", "Radius Multiplier", 1f, "Multiplies the radius by this amount.").Value;
			teleDurationMult = ((BaseUnityPlugin)this).Config.Bind<float>("Teleporter", "Duration Multiplier", 1f, "Multiplies the duration by this amount.").Value;
			smallHoldoutRadiusMult = ((BaseUnityPlugin)this).Config.Bind<float>("Small Holdout", "Radius Multiplier", 1f, "Multiplies the radius by this amount.").Value;
			smallHoldoutDurationMult = ((BaseUnityPlugin)this).Config.Bind<float>("Small Holdout", "Duration Multiplier", 1f, "Multiplies the duration by this amount.").Value;
		}

		public void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ReadConfig();
			if (enableExpand)
			{
				object obj = <>c.<>9__6_0;
				if (obj == null)
				{
					hook_UpdateMonstersClear val = delegate(orig_UpdateMonstersClear orig, TeleporterInteraction self)
					{
						//IL_001f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0025: Invalid comparison between Unknown and I4
						//IL_0042: Unknown result type (might be due to invalid IL or missing references)
						//IL_004c: Unknown result type (might be due to invalid IL or missing references)
						orig.Invoke(self);
						if (self.monstersCleared && Object.op_Implicit((Object)(object)self.holdoutZoneController) && (int)self.activationState == 2 && self.chargeFraction > 0.05f && Util.GetItemCountForTeam(self.holdoutZoneController.chargingTeam, Items.FocusConvergence.itemIndex, true, true) <= 0)
						{
							self.holdoutZoneController.currentRadius = 1000000f;
						}
					};
					<>c.<>9__6_0 = val;
					obj = (object)val;
				}
				TeleporterInteraction.UpdateMonstersClear += (hook_UpdateMonstersClear)obj;
			}
			ModifyTeleporters();
			ModifySmallHoldouts();
		}

		private void ModifyTeleporters()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (teleRadiusMult != 1f || teleDurationMult != 1f)
			{
				string[] array = new string[2] { "RoR2/Base/Teleporters/LunarTeleporter Variant.prefab", "RoR2/Base/Teleporters/Teleporter1.prefab" };
				string[] array2 = array;
				foreach (string text in array2)
				{
					ModifyHoldout(Addressables.LoadAssetAsync<GameObject>((object)text).WaitForCompletion(), teleDurationMult, teleRadiusMult);
				}
			}
		}

		private void ModifySmallHoldouts()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (smallHoldoutRadiusMult != 1f || smallHoldoutDurationMult != 1f)
			{
				string[] array = new string[2] { "RoR2/DLC1/DeepVoidPortalBattery/DeepVoidPortalBattery.prefab", "RoR2/Base/NullSafeWard/NullSafeWard.prefab" };
				HoldoutZoneController.Start += new hook_Start(ModifyMoonHoldout);
				string[] array2 = array;
				foreach (string text in array2)
				{
					ModifyHoldout(Addressables.LoadAssetAsync<GameObject>((object)text).WaitForCompletion(), smallHoldoutDurationMult, smallHoldoutRadiusMult);
				}
				string value = Mathf.RoundToInt(15f * smallHoldoutRadiusMult).ToString();
				SetAddressableEntityStateField("RoR2/Base/NullSafeWard/EntityStates.Missions.Arena.NullWard.NullWardBaseState.asset", "wardRadiusOn", value);
			}
		}

		private void ModifyMoonHoldout(orig_Start orig, HoldoutZoneController self)
		{
			if (self.inBoundsObjectiveToken.Contains("OBJECTIVE_MOON_BATTERY"))
			{
				self.baseRadius *= smallHoldoutRadiusMult;
				self.baseChargeDuration *= smallHoldoutDurationMult;
			}
			orig.Invoke(self);
		}

		public static void ModifyHoldout(GameObject gameObject, float durationMult, float radiusMult)
		{
			HoldoutZoneController component = gameObject.GetComponent<HoldoutZoneController>();
			component.baseChargeDuration *= durationMult;
			component.baseRadius *= radiusMult;
		}

		private static bool SetAddressableEntityStateField(string fullEntityStatePath, string fieldName, string value)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			EntityStateConfiguration val = Addressables.LoadAssetAsync<EntityStateConfiguration>((object)fullEntityStatePath).WaitForCompletion();
			for (int i = 0; i < val.serializedFieldsCollection.serializedFields.Length; i++)
			{
				if (val.serializedFieldsCollection.serializedFields[i].fieldName == fieldName)
				{
					val.serializedFieldsCollection.serializedFields[i].fieldValue.stringValue = value;
					return true;
				}
			}
			return false;
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}