Decompiled source of ReaperDeAgro v1.2.0

ReaperDeAgro.dll

Decompiled 6 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("QNCNXW8R")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cb19d511dc21bf63affed6398446ac92d8695c01")]
[assembly: AssemblyProduct("ReaperDeAgro")]
[assembly: AssemblyTitle("ReaperDeAgro")]
[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 ReaperDeAgro
{
	[BepInPlugin("QNCNXW8R.ReaperDeAgro", "ReaperDeAgro", "1.2.0")]
	public class ReaperDeAgro : BaseUnityPlugin
	{
		public static ConfigEntry<bool>? UseAttackTimer;

		public static ConfigEntry<float>? AttackTimerDuration;

		public static ConfigEntry<string>? EndMode;

		public static ConfigEntry<bool>? UseRandomTimer;

		public static ConfigEntry<float>? RandomTimerMin;

		public static ConfigEntry<float>? RandomTimerMax;

		public static ConfigEntry<bool>? EnableLogging;

		internal static ReaperDeAgro Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

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

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Init();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: 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()
		{
		}

		private void Init()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			UseAttackTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("Reaper", "UseAttackTimer", true, "If true, adds a timer to make the Reaper leave attacking state after a specified time");
			AttackTimerDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Reaper", "AttackTimerDuration", 10f, new ConfigDescription("The amount of time (in seconds) the Reaper stays in the attacking state before leaving", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			EndMode = ((BaseUnityPlugin)this).Config.Bind<string>("Reaper", "EndMode", "Divert", new ConfigDescription("What should the Reaper do when the timer runs out: Pause or Divert", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Pause", "Divert" }), Array.Empty<object>()));
			UseRandomTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("Random", "UseRandomTimer", false, "If true, replaces the attack timer with a random value between the Min and Max values");
			RandomTimerMin = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "RandomTimerMin", 5f, new ConfigDescription("Minimum value for random timer, should be less than Max", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 25f), Array.Empty<object>()));
			RandomTimerMax = ((BaseUnityPlugin)this).Config.Bind<float>("Random", "RandomTimerMax", 15f, new ConfigDescription("Maximum value for random timer, should be more than Min", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			EnableLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableLogging", false, "If true, prints debug data to console");
			ConfigEntry<bool>? useAttackTimer = UseAttackTimer;
			if (useAttackTimer != null && useAttackTimer.Value)
			{
				Harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyRunner), "StateAttackPlayer", (Type[])null, (Type[])null), new HarmonyMethod(typeof(ReaperDeAgro), "StateAttackPlayerPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static void StateAttackPlayerPrefix(EnemyRunner __instance)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Invalid comparison between Unknown and I4
			if (UseAttackTimer == null || AttackTimerDuration == null)
			{
				Logger.LogError((object)"Config entries not initialized.");
				return;
			}
			ReaperAttackState reaperAttackState = ((Component)__instance).GetComponent<ReaperAttackState>();
			if ((Object)(object)reaperAttackState == (Object)null)
			{
				reaperAttackState = ((Component)__instance).gameObject.AddComponent<ReaperAttackState>();
			}
			if ((int)__instance.currentState == 7 && reaperAttackState.attackTimer == 0f)
			{
				if ((EnableLogging?.Value).Value)
				{
					Logger.LogInfo((object)"Reaper entered AttackPlayer state. Timer started.");
				}
				if (UseRandomTimer.Value)
				{
					reaperAttackState.timeLimit = Random.Range(RandomTimerMin.Value, RandomTimerMax.Value);
				}
				else
				{
					reaperAttackState.timeLimit = (AttackTimerDuration?.Value).Value;
				}
			}
			if ((int)__instance.currentState != 7)
			{
				return;
			}
			reaperAttackState.attackTimer += Time.deltaTime;
			if ((EnableLogging?.Value).Value)
			{
				Logger.LogInfo((object)$"Attack Timer: {reaperAttackState.attackTimer}s");
			}
			if (!reaperAttackState.playedSound && (double)reaperAttackState.attackTimer >= (double)reaperAttackState.timeLimit - 0.5)
			{
				PlayNotificationSound(__instance);
				reaperAttackState.playedSound = true;
			}
			if (!(reaperAttackState.attackTimer >= reaperAttackState.timeLimit))
			{
				return;
			}
			if (EndMode?.Value == "Pause")
			{
				if ((EnableLogging?.Value).Value)
				{
					Logger.LogInfo((object)$"Attack timer exceeded {reaperAttackState.timeLimit}s, switching to StateStun.");
				}
				__instance.enemy.Freeze(2f);
				__instance.UpdateState((State)15);
			}
			else
			{
				if ((EnableLogging?.Value).Value)
				{
					Logger.LogInfo((object)$"Attack timer exceeded {reaperAttackState.timeLimit}s, switching to StateLeave.");
				}
				__instance.enemy.Freeze(0.5f);
				__instance.UpdateState((State)16);
			}
			reaperAttackState.attackTimer = 0f;
			reaperAttackState.playedSound = false;
		}

		public static void PlayNotificationSound(EnemyRunner __instance)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if ((EnableLogging?.Value).Value)
			{
				Logger.LogInfo((object)"Playing sound");
			}
			AudioClip val = ((IEnumerable<AudioClip>)Resources.FindObjectsOfTypeAll<AudioClip>()).FirstOrDefault((Func<AudioClip, bool>)((AudioClip c) => ((Object)c).name.Equals("enemy runner death")));
			if ((Object)(object)val != (Object)null)
			{
				Vector3 position = __instance.enemy.CenterTransform.position;
				AudioSource.PlayClipAtPoint(val, position);
			}
			else
			{
				Logger.LogWarning((object)"AudioClip 'enemy runner death' not found.");
			}
		}
	}
	public class ReaperAttackState : MonoBehaviour
	{
		public float attackTimer = 0f;

		public float timeLimit = 0f;

		public bool playedSound = false;
	}
}