Decompiled source of HoarderBugUseItems v1.0.3

HoarderBugUseItems.dll

Decompiled 6 months ago
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 GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HoarderBugUseItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoarderBugUseItems")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c2424393-dc9d-444d-9bd7-6cff11a0addb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HoarderBugUseItems
{
	[BepInPlugin("mattplays-HoarderBugUseItems", "HoarderBugUseItems", "1.0.0")]
	public class HoarderBugUseItems : BaseUnityPlugin
	{
		private const string modGUID = "mattplays-HoarderBugUseItems";

		private const string modName = "HoarderBugUseItems";

		private const string modVersion = "1.0.0";

		private static string boomBoxAudioFile = "boomBoxAudio.mp3";

		private static string uPath = Path.Combine(Paths.PluginPath + "\\mattplays-HoarderBugUseItems\\");

		private readonly Harmony harmony = new Harmony("mattplays-HoarderBugUseItems");

		private static HoarderBugUseItems instance;

		internal ManualLogSource mls;

		internal static AudioClip boomBoxAudioClip;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("mattplays-HoarderBugUseItems");
			harmony.PatchAll();
			boomBoxAudioClip = LoadAudioClip(uPath + boomBoxAudioFile);
			mls.LogInfo((object)"Loaded mattplays-HoarderBugUseItems");
		}

		private static AudioClip LoadAudioClip(string filepath)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Invalid comparison between Unknown and I4
			ManualLogSource val = Logger.CreateLogSource("mattplays-HoarderBugUseItems");
			val.LogInfo((object)("Loading audio clip from " + filepath));
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(filepath, (AudioType)13);
			audioClip.SendWebRequest();
			while (!audioClip.isDone)
			{
			}
			if (audioClip.error != null)
			{
				val.LogError((object)"Failed to load audio clip");
			}
			AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
			if (Object.op_Implicit((Object)(object)content) && (int)content.loadState == 2)
			{
				val.LogInfo((object)"Loaded audio clip successfully!");
				return content;
			}
			return null;
		}
	}
}
namespace HoarderBugUseItems.Patches
{
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal class HoarderBugUseItemPatch
	{
		private static float timeSinceLastTransmitted;

		private static float timeSinceLastFireGun;

		private static float timeSinceLastUseFlashlight;

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static bool UpdatePrefix(HoarderBugAI __instance)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			HoarderBugItem heldItem = ((Component)__instance).GetComponent<HoarderBugAI>().heldItem;
			ManualLogSource val = Logger.CreateLogSource("HoarderBugUseItems");
			if (heldItem != null && !((EnemyAI)__instance).isEnemyDead)
			{
				GrabbableObject itemGrabbableObject = heldItem.itemGrabbableObject;
				if (((Object)itemGrabbableObject).name.StartsWith("StunGrenade"))
				{
					ActivateStunGrenade((StunGrenadeItem)itemGrabbableObject);
				}
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<NoisemakerProp>() != (Object)null)
				{
					ActivateNoisemakerProp((NoisemakerProp)itemGrabbableObject);
				}
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<BoomboxItem>() != (Object)null)
				{
					ActivateBoombox((BoomboxItem)itemGrabbableObject);
				}
				timeSinceLastTransmitted += Time.deltaTime;
				timeSinceLastFireGun += Time.deltaTime;
				timeSinceLastUseFlashlight += Time.deltaTime;
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<FlashlightItem>() != (Object)null && timeSinceLastUseFlashlight >= 2f)
				{
					ActivateFlashlight((FlashlightItem)itemGrabbableObject);
					timeSinceLastUseFlashlight = 0f;
				}
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<WalkieTalkie>() != (Object)null && timeSinceLastTransmitted >= 5f)
				{
					val.LogInfo((object)"5 Seconds since last Walkie Transmission.");
					ActivateWalkieTalkie((WalkieTalkie)itemGrabbableObject, __instance);
					timeSinceLastTransmitted = 0f;
				}
				if ((Object)(object)((Component)itemGrabbableObject).GetComponent<ShotgunItem>() != (Object)null && timeSinceLastFireGun >= 1.75f)
				{
					ActivateShotgunItem((ShotgunItem)itemGrabbableObject, __instance);
					timeSinceLastFireGun = 0f;
				}
			}
			return true;
		}

		private static void ActivateStunGrenade(StunGrenadeItem item)
		{
			item.pinPulled = true;
			((GrabbableObject)item).FallWithCurve();
			((GrabbableObject)item).DestroyObjectInHand((PlayerControllerB)null);
		}

		private static void ActivateNoisemakerProp(NoisemakerProp item)
		{
			if (!((GrabbableObject)item).RequireCooldown())
			{
				((GrabbableObject)item).ItemActivate(true, true);
			}
		}

		private static void ActivateBoombox(BoomboxItem item)
		{
			if (!item.isPlayingMusic)
			{
				if (item.musicAudios.Length > 1)
				{
					item.musicAudios = (AudioClip[])(object)new AudioClip[1] { HoarderBugUseItems.boomBoxAudioClip };
				}
				((GrabbableObject)item).ItemActivate(true, true);
			}
		}

		private static void ActivateFlashlight(FlashlightItem item)
		{
			item.usingPlayerHelmetLight = false;
			if (!((GrabbableObject)item).isBeingUsed && !((GrabbableObject)item).RequireCooldown())
			{
				((GrabbableObject)item).ItemActivate(true, true);
			}
		}

		private static void ActivateWalkieTalkie(WalkieTalkie item, HoarderBugAI instance)
		{
			List<WalkieTalkie> allWalkieTalkies = WalkieTalkie.allWalkieTalkies;
			if (!((GrabbableObject)item).isBeingUsed)
			{
				item.SwitchWalkieTalkieOn(true);
			}
			if (!allWalkieTalkies.Contains(item))
			{
				allWalkieTalkies.Add(item);
			}
			if (!((Object)(object)instance == (Object)null))
			{
				for (int i = 0; i < allWalkieTalkies.Count; i++)
				{
					RoundManager.PlayRandomClip(allWalkieTalkies[i].thisAudio, instance.chitterSFX, true, 1f, 0);
				}
			}
		}

		private static void ActivateShotgunItem(ShotgunItem item, HoarderBugAI instance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (item.safetyOn)
			{
				item.safetyOn = false;
			}
			if (item.shellsLoaded == 0)
			{
				item.shellsLoaded = 2;
			}
			Vector3 position = ((Component)instance.watchingPlayer).transform.position;
			Vector3 forward = item.shotgunRayPoint.forward;
			item.ShootGun(position, forward);
			item.ShootGunServerRpc(position, forward);
		}
	}
}