Decompiled source of TeleExpansion v1.2.1

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 IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
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.2.1")]
	public class TeleExpansion : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_UpdateMonstersClear <>9__9_0;

			public static Func<Instruction, bool> <>9__11_1;

			public static Func<float, HoldoutZoneController, float> <>9__11_0;

			internal void <Awake>b__9_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;
				}
			}

			internal bool <HoldoutZoneController_DoUpdate>b__11_1(Instruction x)
			{
				return ILPatternMatchingExt.MatchStloc(x, 3);
			}

			internal float <HoldoutZoneController_DoUpdate>b__11_0(float radius, HoldoutZoneController self)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Invalid comparison between Unknown and I4
				if ((int)self.chargingTeam == 1)
				{
					int num = 0;
					foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
					{
						if (instance.isConnected && Object.op_Implicit((Object)(object)instance.master) && (int)instance.master.teamIndex == 1)
						{
							num++;
						}
					}
					if (num > 4)
					{
						radius *= 1f + (float)Mathf.Min(largePlayercountMaxPlayers, num - 4) * largePlayercountMultPerPlayer;
					}
				}
				return radius;
			}
		}

		public static bool enableExpand = true;

		public static bool largePlayercountMult = true;

		public static float largePlayercountMultPerPlayer = 0.1f;

		public static int largePlayercountMaxPlayers = 8;

		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;
			largePlayercountMult = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Large Playercount Multiplier", true, "Holdout radius is increased when above 4 players.").Value;
			largePlayercountMultPerPlayer = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Large Playercount Multiplier Per Player", 0.1f, "Radius increase per player over 4.").Value;
			largePlayercountMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Large Playercount Max Increases", 8, "Maximum amount of radius increases to apply.").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__9_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__9_0 = val;
					obj = (object)val;
				}
				TeleporterInteraction.UpdateMonstersClear += (hook_UpdateMonstersClear)obj;
			}
			ModifyTeleporters();
			ModifySmallHoldouts();
			ModifyLargePlayercount();
		}

		private void ModifyLargePlayercount()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			if (largePlayercountMult)
			{
				HoldoutZoneController.DoUpdate += new Manipulator(HoldoutZoneController_DoUpdate);
			}
		}

		private 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>)delegate(float radius, HoldoutZoneController self)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Invalid comparison between Unknown and I4
					//IL_0045: Unknown result type (might be due to invalid IL or missing references)
					//IL_004b: Invalid comparison between Unknown and I4
					if ((int)self.chargingTeam == 1)
					{
						int num = 0;
						foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
						{
							if (instance.isConnected && Object.op_Implicit((Object)(object)instance.master) && (int)instance.master.teamIndex == 1)
							{
								num++;
							}
						}
						if (num > 4)
						{
							radius *= 1f + (float)Mathf.Min(largePlayercountMaxPlayers, num - 4) * largePlayercountMultPerPlayer;
						}
					}
					return radius;
				});
			}
			else
			{
				Debug.LogError((object)"TeleExpansion: HoldoutZoneController_DoUpdate IL hook failed.");
			}
		}

		private void HoldoutZoneController_Awake(orig_Awake orig, HoldoutZoneController self)
		{
			throw new NotImplementedException();
		}

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