Decompiled source of BonusItemSFX v1.0.0

BonusItemSFX.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using loaforcsSoundAPI;
using loaforcsSoundAPI.SoundPacks.Data.Conditions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ConfigurableJesterFear")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConfigurableJesterFear")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("79bad70e-de72-4815-a1f5-2f5317de4abd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BonusItemSFX;

internal class ConfigHandler : MonoBehaviour
{
	public static ConfigEntry<bool> debugMode;

	public static ConfigEntry<bool> useValueThreshold;

	public static ConfigEntry<int> valueThreshold;

	public static ConfigEntry<string> itemWhitelist;

	public static ConfigEntry<bool> whitelistIgnoresThreshold;

	public static ConfigEntry<bool> whitelistOnly;

	public static ConfigEntry<float> SFXCooldown;

	public static void Init(ConfigFile config)
	{
		debugMode = config.Bind<bool>("Debugging", "Print Debug Info", false, "If true, prints debug info into the log, namely telling you the 'Item name' of every last item collected in the ship, useful for the Whitelist or for the SoundAPI condition.");
		useValueThreshold = config.Bind<bool>("Value Threshold", "Use Value Threshold?", true, "If true, items must be at the threshold's value or higher to trigger the special sound effect when collected.");
		valueThreshold = config.Bind<int>("Value Threshold", "Value Threshold", 250, "If 'Use Value Threshold' is enabled, then items must be this value or higher to trigger the special sound effect when collected.");
		itemWhitelist = config.Bind<string>("Item Whitelist", "Whitelist", "Apparatus,Upturned Apparatus,Demonic Painting,Majora's Mask,Bozo-Apparatus,Haunted apparatus,Pink Apparatus,Plasma apparatus,Red Apparatus,Team Purple Apparatus,Green Team Apparatus,Toxic Apparatus,Baboon Hawk Head", "A comma seperated list of items to play sound effects for when collected, depending on the other settings.");
		whitelistIgnoresThreshold = config.Bind<bool>("Item Whitelist", "Whitelist ignores threshold?", true, "If true, any items in the whitelist will trigger the sound when collected, regardless of value. If false, items in the whitelist must also reach the value requirement to play a sound (if 'Use Value Threshold' is enabled)");
		whitelistOnly = config.Bind<bool>("Item Whitelist", "Whitelist Only", false, "If true, ONLY items in the whitelist can trigger a sound effect. If false, the whitelist is just used to bypass the Value Threshold, meaning any items collected above the Value Threshold can trigger a sound still. Disabling this AND disabling the Value Threshold (or making it 0) will mean ANY item collected will play the sound effect, as there is no filter!!");
		SFXCooldown = config.Bind<float>("Sound", "SFX Cooldown", 2f, "The cooldown between sound effects to prevent them overlapping (Useful if you collect many high-value items at once, like with the Cruiser). Set to 0 if you don't want any cooldown!");
	}
}
[BepInPlugin("ZetaArcade.BonusItemSFX", "BonusItemSFX", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BonusItemSFX : BaseUnityPlugin
{
	private const string modGUID = "ZetaArcade.BonusItemSFX";

	private const string modName = "BonusItemSFX";

	private const string modVersion = "0.0.1";

	private Harmony harmony = new Harmony("ZetaArcade.BonusItemSFX");

	public static ManualLogSource Logger;

	public static BonusItemSFX Instance;

	public static AssetBundle MyCustomAssets;

	public static string LastCollectedItemName;

	public AudioClip fancyItemCollect;

	public static bool SFXOnCooldown;

	private Coroutine cooldownCoroutine;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		Logger = ((BaseUnityPlugin)this).Logger;
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		MyCustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "bonusitemsfx"));
		if ((Object)(object)MyCustomAssets == (Object)null)
		{
			Logger.LogError((object)"Failed to load custom assets!");
			return;
		}
		fancyItemCollect = MyCustomAssets.LoadAsset<AudioClip>("Assets/zetasstuff/LuigiKeyGet.ogg");
		if ((Object)(object)fancyItemCollect == (Object)null)
		{
			Logger.LogError((object)"Failed to load key get sound effect!");
		}
		ConfigHandler.Init(((BaseUnityPlugin)this).Config);
		harmony.PatchAll(typeof(BonusItemSFX));
		harmony.PatchAll(typeof(HUDManager));
		harmony.PatchAll(typeof(HUDManagerSFXPatch));
		SoundAPI.RegisterAll(Assembly.GetExecutingAssembly());
		Logger.LogInfo((object)"Plugin is loaded!");
	}

	public void BeginSFXCooldown()
	{
		if (cooldownCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(cooldownCoroutine);
		}
		cooldownCoroutine = ((MonoBehaviour)this).StartCoroutine(ResetCooldownAfterDelay(ConfigHandler.SFXCooldown.Value));
	}

	private IEnumerator ResetCooldownAfterDelay(float delay)
	{
		SFXOnCooldown = true;
		yield return (object)new WaitForSeconds(delay);
		SFXOnCooldown = false;
	}
}
[HarmonyPatch(typeof(HUDManager))]
public class HUDManagerSFXPatch
{
	[SoundAPICondition("LethalCompany:lastitem", false, null)]
	public class CollectedItemCondition : Condition
	{
		public string Value { get; internal set; }

		public override bool Evaluate(IContext context)
		{
			BonusItemSFX.Logger.LogInfo((object)"Entering SoundAPI Condition");
			string lastCollectedItemName = BonusItemSFX.LastCollectedItemName;
			if (string.Equals(Value, lastCollectedItemName, StringComparison.InvariantCultureIgnoreCase))
			{
				BonusItemSFX.Logger.LogInfo((object)("Last item collected IS the same as specified (" + lastCollectedItemName + " DOES match " + Value + ")"));
			}
			else
			{
				BonusItemSFX.Logger.LogInfo((object)("Last item collected is NOT the same as specified (" + lastCollectedItemName + " does NOT match " + Value + ")"));
			}
			return string.Equals(Value, lastCollectedItemName, StringComparison.InvariantCultureIgnoreCase);
		}
	}

	[HarmonyPatch("DisplayNewScrapFound")]
	[HarmonyPrefix]
	private static void DisplayNewScrapFoundPatch(ref HUDManager __instance)
	{
		if (__instance.itemsToBeDisplayed.Count <= 0)
		{
			return;
		}
		if ((Object)(object)__instance.itemsToBeDisplayed[0] == (Object)null || (Object)(object)__instance.itemsToBeDisplayed[0].itemProperties.spawnPrefab == (Object)null)
		{
			__instance.itemsToBeDisplayed.Clear();
			return;
		}
		BonusItemSFX.LastCollectedItemName = __instance.itemsToBeDisplayed[0].itemProperties.itemName;
		if (ConfigHandler.debugMode.Value)
		{
			BonusItemSFX.Logger.LogInfo((object)("Last collected item name is: " + __instance.itemsToBeDisplayed[0].itemProperties.itemName));
		}
		if (BonusItemSFX.SFXOnCooldown)
		{
			return;
		}
		if (ConfigHandler.whitelistOnly.Value)
		{
			if (ConfigHandler.itemWhitelist.Value == null && !(ConfigHandler.itemWhitelist.Value != ""))
			{
				return;
			}
			string[] source = (from s in ConfigHandler.itemWhitelist.Value.Split(new char[1] { ',' })
				select s.Trim().ToLowerInvariant()).ToArray();
			if (source.Contains(BonusItemSFX.LastCollectedItemName.ToLowerInvariant()))
			{
				if (ConfigHandler.whitelistIgnoresThreshold.Value || !ConfigHandler.useValueThreshold.Value)
				{
					__instance.UIAudio.PlayOneShot(BonusItemSFX.Instance.fancyItemCollect);
					BonusItemSFX.Instance.BeginSFXCooldown();
				}
				else if (__instance.itemsToBeDisplayed[0].scrapValue >= ConfigHandler.valueThreshold.Value)
				{
					__instance.UIAudio.PlayOneShot(BonusItemSFX.Instance.fancyItemCollect);
					BonusItemSFX.Instance.BeginSFXCooldown();
				}
			}
		}
		else
		{
			string[] source2 = (from s in ConfigHandler.itemWhitelist.Value.Split(new char[1] { ',' })
				select s.Trim().ToLowerInvariant()).ToArray();
			if (ConfigHandler.whitelistIgnoresThreshold.Value && source2.Contains(BonusItemSFX.LastCollectedItemName.ToLowerInvariant()))
			{
				__instance.UIAudio.PlayOneShot(BonusItemSFX.Instance.fancyItemCollect);
				BonusItemSFX.Instance.BeginSFXCooldown();
			}
			else if (!ConfigHandler.useValueThreshold.Value)
			{
				__instance.UIAudio.PlayOneShot(BonusItemSFX.Instance.fancyItemCollect);
				BonusItemSFX.Instance.BeginSFXCooldown();
			}
			else if (__instance.itemsToBeDisplayed[0].scrapValue >= ConfigHandler.valueThreshold.Value)
			{
				__instance.UIAudio.PlayOneShot(BonusItemSFX.Instance.fancyItemCollect);
				BonusItemSFX.Instance.BeginSFXCooldown();
			}
		}
	}
}