Decompiled source of GiantEnemySpider FIXED v1.0.0

Spantle.GiantEnemySpider.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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("Spantle.GiantEnemySpider")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Bunker Spiders will play the iconic Jerma 'Giant Enemy Spider' song while chasing a player. A fixed version of Skellinghoff's mod.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GiantEnemySpider")]
[assembly: AssemblyTitle("Spantle.GiantEnemySpider")]
[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.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("Spantle.GiantEnemySpider", "GiantEnemySpider", "1.0.0")]
	public class GiantEnemySpiderPlugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("Spantle.GiantEnemySpider");

		public static ManualLogSource logger;

		public static AudioClip giantEnemySpiderIntroAudioClip;

		public static AudioClip giantEnemySpiderLoopAudioClip;

		public static Dictionary<SandSpiderAI, GiantEnemySpider> giantEnemySpiders = new Dictionary<SandSpiderAI, GiantEnemySpider>();

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			AssetBundle obj = AssetBundle.LoadFromMemory(Resources.GiantEnemySpider);
			giantEnemySpiderIntroAudioClip = obj.LoadAsset<AudioClip>("assets/intro.ogg");
			giantEnemySpiderLoopAudioClip = obj.LoadAsset<AudioClip>("assets/loop.ogg");
			harmony.PatchAll(typeof(SandSpiderAI_Patch));
			harmony.PatchAll(typeof(EnemyAI_Patch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Spantle.GiantEnemySpider has loaded! *starts beatboxing*");
		}
	}
	public class GiantEnemySpider
	{
		private bool introPlayed;

		private AudioSource audioSource;

		private float lastPlayed;

		public GiantEnemySpider(AudioSource audioSource)
		{
			this.audioSource = audioSource;
		}

		public void Play()
		{
			if (audioSource.isPlaying)
			{
				if (!introPlayed)
				{
					lastPlayed = Time.time;
				}
				return;
			}
			introPlayed = !(Time.time - lastPlayed > GiantEnemySpiderPlugin.giantEnemySpiderIntroAudioClip.length);
			if (introPlayed)
			{
				audioSource.clip = GiantEnemySpiderPlugin.giantEnemySpiderLoopAudioClip;
				audioSource.loop = true;
			}
			else
			{
				audioSource.clip = GiantEnemySpiderPlugin.giantEnemySpiderIntroAudioClip;
				audioSource.loop = false;
			}
			audioSource.Play();
		}

		public void Stop()
		{
			if (introPlayed && audioSource.isPlaying)
			{
				audioSource.Stop();
				lastPlayed = Time.time;
			}
		}
	}
	[HarmonyPatch(typeof(SandSpiderAI))]
	public static class SandSpiderAI_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(SandSpiderAI), "Start")]
		private static void Start(SandSpiderAI __instance)
		{
			Jermaify(__instance);
		}

		private static GiantEnemySpider Jermaify(SandSpiderAI __instance)
		{
			if (!GiantEnemySpiderPlugin.giantEnemySpiders.TryGetValue(__instance, out var value))
			{
				value = new GiantEnemySpider(((Component)__instance).gameObject.GetComponent<AudioSource>());
				GiantEnemySpiderPlugin.giantEnemySpiders.Add(__instance, value);
			}
			return value;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SandSpiderAI), "Update")]
		private static void Update(SandSpiderAI __instance)
		{
			GiantEnemySpider giantEnemySpider = Jermaify(__instance);
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 2)
			{
				giantEnemySpider.Play();
			}
			else
			{
				giantEnemySpider.Stop();
			}
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	public static class EnemyAI_Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyAI), "OnDestroy")]
		private static void OnDestroy(EnemyAI __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			GiantEnemySpiderPlugin.giantEnemySpiders.Remove((SandSpiderAI)__instance);
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("GiantEnemySpider.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] GiantEnemySpider => (byte[])ResourceManager.GetObject("GiantEnemySpider", resourceCulture);

		internal Resources()
		{
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Spantle.GiantEnemySpider";

		public const string PLUGIN_NAME = "GiantEnemySpider";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}