Decompiled source of AllMyFellasSingleFly v1.0.0

BepInEx/plugins/AllMyFellasSingleFly/AllMyFellasSingleFly.dll

Decompiled 18 hours 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 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: AssemblyCompany("AllMyFellasSingleFly")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AllMyFellasSingleFly")]
[assembly: AssemblyTitle("AllMyFellasSingleFly")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 AllMyFellasSingleFly
{
	[BepInPlugin("com.allmyfellas.singlefly", "AllMyFellasSingleFly", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> HandOff;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			HandOff = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HandOffToNextFlyingBug", true, "When the bug whose Fly sound is playing stops chasing, another bug that is still chasing takes over and starts its Fly sound. false = silenced bugs stay silent until their own chase ends.");
			new Harmony("com.allmyfellas.singlefly").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"Only one Hoarding Bug Fly sound will play at a time.");
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI), "Update")]
	internal static class SingleFlyPatch
	{
		private static readonly FieldRef<HoarderBugAI, bool> InChase = AccessTools.FieldRefAccess<HoarderBugAI, bool>("inChase");

		private static HoarderBugAI owner;

		private static readonly HashSet<HoarderBugAI> chasing = new HashSet<HoarderBugAI>();

		[HarmonyPostfix]
		private static void Postfix(HoarderBugAI __instance)
		{
			if ((Object)(object)owner == (Object)null || ((EnemyAI)owner).isEnemyDead || !InChase.Invoke(owner))
			{
				owner = null;
				chasing.RemoveWhere((HoarderBugAI bug) => (Object)(object)bug == (Object)null);
			}
			if (!InChase.Invoke(__instance) || ((EnemyAI)__instance).isEnemyDead)
			{
				chasing.Remove(__instance);
				return;
			}
			bool flag = chasing.Add(__instance);
			if ((Object)(object)owner == (Object)null)
			{
				if (flag)
				{
					owner = __instance;
				}
				else if (Plugin.HandOff.Value)
				{
					owner = __instance;
					((EnemyAI)__instance).creatureSFX.clip = __instance.bugFlySFX;
					((EnemyAI)__instance).creatureSFX.Play();
				}
			}
			else if ((Object)(object)owner != (Object)(object)__instance && flag)
			{
				((EnemyAI)__instance).creatureSFX.Stop();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.allmyfellas.singlefly";

		public const string PLUGIN_NAME = "AllMyFellasSingleFly";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}