Decompiled source of GiantEnemySpider v1.1.0

BepInEx/plugins/GiantEnemySpider.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GiantEnemySpider.Patches;
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("GiantEnemySpider")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("GiantEnemySpider")]
[assembly: AssemblyTitle("GiantEnemySpider")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GiantEnemySpider
{
	[BepInPlugin("GiantEnemySpider", "GiantEnemySpider", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static AudioClip GiantEnemySpiderSound;

		private readonly Harmony harmony = new Harmony("GiantEnemySpider");

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected I4, but got Unknown
			try
			{
				if ((Object)(object)Instance == (Object)null)
				{
					Instance = this;
				}
				harmony.PatchAll(typeof(Plugin));
				harmony.PatchAll(typeof(SandSpider));
				GiantEnemySpiderSound = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "giantenemyspider.bundle")).LoadAsset<AudioClip>("assets/GiantEnemySpider.wav");
				AudioDataLoadState loadState = GiantEnemySpiderSound.loadState;
				switch ((int)loadState)
				{
				case 2:
					((BaseUnityPlugin)this).Logger.LogInfo((object)"GiantEnemySpiderSound is loaded and ready to play.");
					break;
				case 1:
					((BaseUnityPlugin)this).Logger.LogInfo((object)"GiantEnemySpiderSound is currently loading.");
					break;
				case 0:
					((BaseUnityPlugin)this).Logger.LogError((object)"GiantEnemySpiderSound is not loaded.");
					break;
				case 3:
					((BaseUnityPlugin)this).Logger.LogError((object)"GiantEnemySpiderSound failed to load.");
					break;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugins GiantEnemySpiderv1.1.0 is loaded!");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Plugin GiantEnemySpider failed to load!");
				((BaseUnityPlugin)this).Logger.LogError((object)("Exception: " + ex.Message));
				((BaseUnityPlugin)this).Logger.LogError((object)("Stack Trace: " + ex.StackTrace));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "GiantEnemySpider";

		public const string PLUGIN_NAME = "GiantEnemySpider";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace GiantEnemySpider.Patches
{
	[HarmonyPatch(typeof(SandSpiderAI))]
	internal class SandSpider
	{
		private const int BEHAVIOUR_STATE_CHASING = 2;

		private static readonly ManualLogSource logger = Logger.CreateLogSource("SandEnemyPatch");

		private static readonly Dictionary<SandSpiderAI, AudioSource> audioSources = new Dictionary<SandSpiderAI, AudioSource>();

		private static readonly Dictionary<SandSpiderAI, bool> isPlayingFlags = new Dictionary<SandSpiderAI, bool>();

		private const float LOOP_START = 5.58f;

		private const float LOOP_END = 8.036f;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void SandEnemyPatchStart(SandSpiderAI __instance)
		{
			AudioSource component = ((Component)__instance).GetComponent<AudioSource>();
			audioSources[__instance] = component;
			isPlayingFlags[__instance] = false;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void SandEnemyPatch(SandSpiderAI __instance)
		{
			if (((EnemyAI)__instance).movingTowardsTargetPlayer && !((EnemyAI)__instance).isEnemyDead)
			{
				if ((Object)(object)audioSources[__instance] != (Object)null)
				{
					if (!isPlayingFlags[__instance])
					{
						audioSources[__instance].clip = Plugin.GiantEnemySpiderSound;
						audioSources[__instance].Play();
						isPlayingFlags[__instance] = true;
					}
					else if (audioSources[__instance].time > 8.036f)
					{
						audioSources[__instance].time = 5.58f;
					}
				}
			}
			else if (isPlayingFlags[__instance] && (Object)(object)audioSources[__instance] != (Object)null)
			{
				audioSources[__instance].Stop();
				isPlayingFlags[__instance] = false;
			}
		}
	}
}