Decompiled source of RespawnNoiseControl v1.0.0

RespawnNoiseControl.dll

Decompiled 4 days 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 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("zabu")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("zabumod")]
[assembly: AssemblyTitle("zabumod")]
[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 REPOJP.RespawnNoiseControl
{
	[BepInPlugin("REPOJP.RespawnNoiseControl", "RespawnNoiseControl", "1.0.1")]
	public sealed class RespawnNoiseControlPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "REPOJP.RespawnNoiseControl";

		public const string PluginName = "RespawnNoiseControl";

		public const string PluginVersion = "1.0.1";

		internal static ManualLogSource Log;

		internal static RespawnNoiseControlPlugin Instance;

		private Harmony _harmony = null;

		internal static ConfigEntry<bool> EnableMod;

		internal static ConfigEntry<float> RespawnNoiseThreshold;

		internal static ConfigEntry<float> RespawnDecreaseSeconds;

		private void Awake()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			try
			{
				((Component)this).transform.parent = null;
				((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Instance = this;
				Log = ((BaseUnityPlugin)this).Logger;
				EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enable or disable this mod.このMODの有効無効");
				RespawnNoiseThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RespawnNoiseThreshold", 10f, new ConfigDescription("Noise threshold required to reduce enemy respawn timer.敵のリスポーン時間短縮が発生する音量しきい値", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
				RespawnDecreaseSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RespawnDecreaseSeconds", 5f, new ConfigDescription("How many seconds to reduce the enemy respawn timer when the threshold is met.しきい値到達時に敵のリスポーン時間を何秒短縮するか", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
				_harmony = new Harmony("REPOJP.RespawnNoiseControl");
				_harmony.PatchAll();
				Log.LogInfo((object)"RespawnNoiseControl 1.0.1 loaded");
				Log.LogInfo((object)$"EnableMod = {EnableMod.Value}");
				Log.LogInfo((object)$"RespawnNoiseThreshold = {RespawnNoiseThreshold.Value}");
				Log.LogInfo((object)$"RespawnDecreaseSeconds = {RespawnDecreaseSeconds.Value}");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("Failed to initialize {0}\n{1}", "RespawnNoiseControl", arg));
			}
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("Failed to unpatch {0}\n{1}", "RespawnNoiseControl", arg));
			}
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "SetInvestigate")]
	internal static class EnemyDirectorSetInvestigatePatch
	{
		private static bool Prefix(EnemyDirector __instance, Vector3 position, float radius, bool pathfindOnly = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!RespawnNoiseControlPlugin.EnableMod.Value)
				{
					return true;
				}
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					return false;
				}
				if (__instance.debugInvestigate)
				{
					GameObject val = Object.Instantiate<GameObject>(AssetManager.instance.debugEnemyInvestigate, position, Quaternion.identity);
					DebugEnemyInvestigate component = val.GetComponent<DebugEnemyInvestigate>();
					if ((Object)(object)component != (Object)null)
					{
						component.radius = radius;
					}
				}
				foreach (EnemyParent item in __instance.enemiesSpawned)
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					if (!item.Spawned)
					{
						if (radius >= RespawnNoiseControlPlugin.RespawnNoiseThreshold.Value)
						{
							item.DisableDecrease(RespawnNoiseControlPlugin.RespawnDecreaseSeconds.Value);
						}
					}
					else if (!((Object)(object)item.Enemy == (Object)null) && item.Enemy.HasStateInvestigate && Vector3.Distance(position, ((Component)item.Enemy).transform.position) / item.Enemy.StateInvestigate.rangeMultiplier < radius)
					{
						item.Enemy.StateInvestigate.Set(position, pathfindOnly);
					}
				}
				return false;
			}
			catch (Exception arg)
			{
				RespawnNoiseControlPlugin.Log.LogError((object)$"Failed in EnemyDirector.SetInvestigate patch\n{arg}");
				return true;
			}
		}
	}
}