Decompiled source of MentalistAttackModifier v1.1.0

FloaterAttack.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Kai")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FloaterAttack")]
[assembly: AssemblyTitle("FloaterAttack")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 FloaterAttack
{
	[BepInPlugin("Kai.FloaterAttack", "FloaterAttack", "2.0")]
	public class FloaterAttack : BaseUnityPlugin
	{
		public static float RuntimeRange;

		public static int RuntimeDamage;

		public static ConfigEntry<float> AttackRange;

		public static ConfigEntry<int> SmashDamage;

		public static ConfigEntry<bool> VisualAutoScale;

		public static ConfigEntry<float> VisualScaleMultiplier;

		public static ConfigEntry<bool> EnableInvestigateSound;

		public static ConfigEntry<float> ChargeInvestigateRange;

		public static ConfigEntry<float> SmashInvestigateRange;

		internal static FloaterAttack Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			AttackRange = ((BaseUnityPlugin)this).Config.Bind<float>("Floater", "AttackRange", 4f, new ConfigDescription("Floater attack radius (0 - 100)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			SmashDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Floater", "SmashDamage", 50, new ConfigDescription("Floater smash damage (0 - 300)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
			VisualAutoScale = ((BaseUnityPlugin)this).Config.Bind<bool>("Floater", "VisualAutoScale", true, "Automatically scale visual effect based on AttackRange");
			VisualScaleMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Floater", "VisualScaleMultiplier", 1f, new ConfigDescription("Manual visual scale multiplier (used when VisualAutoScale is false)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			EnableInvestigateSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Floater", "EnableInvestigateSound", true, "Enable enemy investigate sound injection");
			ChargeInvestigateRange = ((BaseUnityPlugin)this).Config.Bind<float>("Floater", "ChargeInvestigateRange", 15f, new ConfigDescription("Investigate radius during Charge animation (0 - 100)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			SmashInvestigateRange = ((BaseUnityPlugin)this).Config.Bind<float>("Floater", "SmashInvestigateRange", 30f, new ConfigDescription("Investigate radius during Smash (0 - 100)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_0019: 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: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch(typeof(FloaterAttackLogic), "GetAllWithinRange")]
	public static class FloaterRangePatch
	{
		private static void Prefix(FloaterAttackLogic __instance)
		{
			FieldInfo field = typeof(FloaterAttackLogic).GetField("range", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(__instance, FloaterAttack.RuntimeRange);
			}
		}
	}
	[HarmonyPatch(typeof(FloaterAttackLogic), "StateSmash")]
	public static class FloaterSmashPatch
	{
		private static void Prefix(FloaterAttackLogic __instance)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			typeof(FloaterAttackLogic).GetField("damage", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, FloaterAttack.RuntimeDamage);
			if (FloaterAttack.EnableInvestigateSound.Value && SemiFunc.IsMasterClientOrSingleplayer())
			{
				EnemyDirector.instance.SetInvestigate(((Component)__instance).transform.position, Mathf.Clamp(FloaterAttack.SmashInvestigateRange.Value, 0f, 100f), false);
			}
		}
	}
	[HarmonyPatch(typeof(FloaterAttackLogic), "Update")]
	public static class FloaterVisualContinuousPatch
	{
		private static void Postfix(FloaterAttackLogic __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance.sphereEffects == (Object)null) && (int)__instance.state != 5 && (int)__instance.state != 4)
			{
				float num2;
				if (FloaterAttack.VisualAutoScale.Value)
				{
					float num = Mathf.Clamp(FloaterAttack.RuntimeRange, 0f, 100f);
					num2 = num * 0.3f;
				}
				else
				{
					num2 = 1.2f * Mathf.Clamp(FloaterAttack.VisualScaleMultiplier.Value, 0f, 10f);
				}
				__instance.sphereEffects.localScale = Vector3.one * num2;
				if ((Object)(object)__instance.attackLight != (Object)null)
				{
					__instance.attackLight.range = num2 / 0.3f;
					__instance.attackLight.intensity = num2 * 4f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(EnemyFloaterAnim), "Update")]
	public static class FloaterChargeInvestigatePatch
	{
		private static readonly Dictionary<EnemyFloaterAnim, float> timer = new Dictionary<EnemyFloaterAnim, float>();

		private static void Postfix(EnemyFloaterAnim __instance)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (!FloaterAttack.EnableInvestigateSound.Value || !SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)__instance.controller == (Object)null)
			{
				return;
			}
			if ((int)__instance.controller.currentState == 7)
			{
				if (!timer.ContainsKey(__instance))
				{
					timer[__instance] = 0f;
				}
				timer[__instance] -= Time.deltaTime;
				if (timer[__instance] <= 0f)
				{
					EnemyDirector.instance.SetInvestigate(((Component)__instance).transform.position, Mathf.Clamp(FloaterAttack.ChargeInvestigateRange.Value, 0f, 100f), false);
					timer[__instance] = 0.6f;
				}
			}
			else if (timer.ContainsKey(__instance))
			{
				timer.Remove(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(PunManager), "Start")]
	public static class AttachSyncComponentPatch
	{
		private static void Postfix(PunManager __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<FloaterNetworkSync>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<FloaterNetworkSync>();
			}
		}
	}
	public class FloaterNetworkSync : MonoBehaviourPun
	{
		[PunRPC]
		public void SyncFloaterSettingsRPC(float range, int damage, PhotonMessageInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				FloaterAttack.RuntimeRange = range;
				FloaterAttack.RuntimeDamage = damage;
			}
		}
	}
	[HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")]
	public static class SyncOnLevelStartPatch
	{
		private static void Postfix()
		{
			if (PhotonNetwork.IsMasterClient)
			{
				FloaterAttack.RuntimeRange = FloaterAttack.AttackRange.Value;
				FloaterAttack.RuntimeDamage = FloaterAttack.SmashDamage.Value;
				PunManager.instance.photonView.RPC("SyncFloaterSettingsRPC", (RpcTarget)1, new object[2]
				{
					FloaterAttack.RuntimeRange,
					FloaterAttack.RuntimeDamage
				});
			}
		}
	}
}