Decompiled source of SPIDERFORK1 DONOTUSE GiantEnemySpider v1.0.3

BepInEx/plugins/GiantEnemySpider.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GiantEnemySpider.Patches;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ClassLibrary11")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary11")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c0e51a55-3229-49c6-b49f-b85f98e9bfce")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GiantEnemySpider
{
	[BepInPlugin("com.giantenemyspider.plugin", "GiantEnemySpider", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static AudioClip GiantEnemySpiderSound;

		private readonly Harmony harmony = new Harmony("com.giantenemyspider.plugin");

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0084: 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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected I4, but got Unknown
			try
			{
				if ((Object)(object)Instance == (Object)null)
				{
					Instance = this;
				}
				harmony.PatchAll(typeof(Plugin));
				harmony.PatchAll(typeof(SandSpider));
				string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "giantenemyspider.bundle");
				AssetBundle val = AssetBundle.LoadFromFile(text);
				GiantEnemySpiderSound = val.LoadAsset<AudioClip>("assets/GiantEnemySpider.wav");
				AudioDataLoadState loadState = GiantEnemySpiderSound.loadState;
				AudioDataLoadState val2 = loadState;
				AudioDataLoadState val3 = val2;
				switch (val3 - 1)
				{
				case 1:
					((BaseUnityPlugin)this).Logger.LogInfo((object)"GiantEnemySpiderSound is loaded and ready to play.");
					break;
				case 0:
					((BaseUnityPlugin)this).Logger.LogInfo((object)"GiantEnemySpiderSound is currently loading.");
					break;
				case 2:
					((BaseUnityPlugin)this).Logger.LogError((object)"GiantEnemySpiderSound failed to load.");
					break;
				default:
					((BaseUnityPlugin)this).Logger.LogError((object)"GiantEnemySpiderSound is not loaded.");
					break;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin GiantEnemySpider v1.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 = "com.giantenemyspider.plugin";

		public const string PLUGIN_NAME = "GiantEnemySpider";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace GiantEnemySpider.Patches
{
	[HarmonyPatch(typeof(SandSpiderAI))]
	internal class SandSpider
	{
		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>();

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

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void SandEnemyPatch(SandSpiderAI __instance)
		{
			bool value2;
			AudioSource value3;
			if (((EnemyAI)__instance).movingTowardsTargetPlayer && !((EnemyAI)__instance).isEnemyDead)
			{
				if (AudioSources.TryGetValue(__instance, out var value) && (Object)(object)value != (Object)null)
				{
					if (!IsPlayingFlags[__instance])
					{
						value.clip = Plugin.GiantEnemySpiderSound;
						value.Play();
						IsPlayingFlags[__instance] = true;
					}
					else if (value.time > 197.46f)
					{
						value.time = 0f;
					}
				}
			}
			else if (IsPlayingFlags.TryGetValue(__instance, out value2) && value2 && AudioSources.TryGetValue(__instance, out value3) && (Object)(object)value3 != (Object)null)
			{
				value3.Stop();
				IsPlayingFlags[__instance] = false;
			}
		}
	}
}