Decompiled source of FFXIV SFX v1.1.2

FFXIVSFX.dll

Decompiled 7 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FFXIVSFX.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("FFXIVSFX")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FFXIVSFX")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dcb54def-31ed-4d23-b5f5-b419f9465400")]
[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 FFXIVSFX
{
	[BepInPlugin("AddranorLive-FFXIVSFX", "FFXIVSFX", "0.0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal const string modGUID = "AddranorLive-FFXIVSFX";

		internal const string modName = "FFXIVSFX";

		internal const string modVersion = "0.0.1.0";

		internal readonly Harmony harmony = new Harmony("AddranorLive-FFXIVSFX");

		internal static Plugin Instance;

		internal static ManualLogSource MLS;

		internal static AssetBundle ModBundle;

		internal static string Location;

		internal static ConfigEntry<bool> sfx_RadMech;

		internal static ConfigEntry<bool> sfx_Jester;

		internal static ConfigEntry<bool> sfx_Flowerman;

		internal static ConfigEntry<bool> sfx_HoarderBug;

		internal static ConfigEntry<bool> sfx_Airhorn;

		internal static ConfigEntry<bool> sfx_Clownhorn;

		internal static ConfigEntry<bool> sfx_GiftBox;

		internal static ConfigEntry<bool> sfx_Boombox;

		internal static ConfigEntry<bool> sfx_Player;

		internal static ConfigEntry<bool> sfx_Dropship;

		internal static ConfigEntry<bool> sfx_Ship;

		internal static ConfigEntry<bool> sfx_SystemSounds;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Location = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("AddranorLive-FFXIVSFX.dll".ToCharArray());
			ModBundle = AssetBundle.LoadFromFile(Location + "FFXIVSFX".ToLower());
			MLS = Logger.CreateLogSource("AddranorLive-FFXIVSFX");
			if (!((Object)(object)ModBundle == (Object)null))
			{
				harmony.PatchAll(typeof(Plugin));
				Patch_Enemies();
				Patch_Items();
				Patch_Misc();
				LogInfo("Mod has been initialized.");
			}
		}

		public void Patch_Enemies()
		{
			BindConfig(ref sfx_Flowerman, "Enemies", "Flowerman");
			BindConfig(ref sfx_RadMech, "Enemies", "Old Bird");
			BindConfig(ref sfx_HoarderBug, "Enemies", "Hoarder Bug");
			BindConfig(ref sfx_Jester, "Enemies", "Jester");
			if (sfx_Flowerman.Value)
			{
				PatchFlowermanAI.sfx_Anger = LoadAssetFromBundle("enemies_flowerman_anger");
				LogInfo("New entry : Flowerman SFX");
			}
			if (sfx_RadMech.Value)
			{
				PatchRadMechAI.sfx_Creature = new List<AudioClip>
				{
					LoadAssetFromBundle("enemies_oldbird_1"),
					LoadAssetFromBundle("enemies_oldbird_2"),
					LoadAssetFromBundle("enemies_oldbird_3"),
					LoadAssetFromBundle("enemies_oldbird_4"),
					LoadAssetFromBundle("enemies_oldbird_5"),
					LoadAssetFromBundle("enemies_oldbird_6")
				};
				LogInfo("New entry : Old Bird SFX");
			}
			if (sfx_Jester.Value)
			{
				PatchJesterAI.sfx_Winding = LoadAssetFromBundle("enemies_jester_windup");
				PatchJesterAI.sfx_Screaming = LoadAssetFromBundle("enemies_jester_chase");
				PatchJesterAI.sfx_PopUp = LoadAssetFromBundle("enemies_jester_popup");
				LogInfo("New entry : Jester SFX");
			}
			if (sfx_HoarderBug.Value)
			{
				PatchHoarderBugAI.sfx_Chitter = LoadAssetFromBundle("enemies_hoarder_chitter");
				LogInfo("New entry : Hoarder Bug SFX");
			}
			harmony.PatchAll(typeof(PatchFlowermanAI));
			harmony.PatchAll(typeof(PatchRadMechAI));
			harmony.PatchAll(typeof(PatchHoarderBugAI));
			harmony.PatchAll(typeof(PatchJesterAI));
		}

		public void Patch_Items()
		{
			BindConfig(ref sfx_Airhorn, "Items", "Airhorn");
			BindConfig(ref sfx_Clownhorn, "Items", "Clownhorn");
			BindConfig(ref sfx_GiftBox, "Items", "Gift Box");
			BindConfig(ref sfx_Boombox, "Items", "Boombox");
			if (sfx_Airhorn.Value)
			{
				PatchNoisemakerProp.sfx_Airhorn = new NoiseMakerPackage("items_airhorn");
				LogInfo("New entry : Airhorn SFX");
			}
			if (sfx_Clownhorn.Value)
			{
				PatchNoisemakerProp.sfx_Clownhorn = new NoiseMakerPackage("items_clownhorn");
				LogInfo("New entry : Clownhorn SFX");
			}
			if (sfx_GiftBox.Value)
			{
				PatchGiftBoxItem.sfx_OpenGift = LoadAssetFromBundle("items_opengiftbox");
				LogInfo("New entry : Gift Box SFX");
			}
			if (sfx_Boombox.Value)
			{
				PatchBoomboxItem.sfx_Musics = new List<AudioClip>
				{
					LoadAssetFromBundle("items_boombox_1", "mp3"),
					LoadAssetFromBundle("items_boombox_2", "mp3"),
					LoadAssetFromBundle("items_boombox_3", "mp3"),
					LoadAssetFromBundle("items_boombox_4", "mp3"),
					LoadAssetFromBundle("items_boombox_5", "mp3")
				};
				LogInfo("New entry : Boombox SFX");
			}
			harmony.PatchAll(typeof(PatchNoisemakerProp));
			harmony.PatchAll(typeof(PatchGiftBoxItem));
			harmony.PatchAll(typeof(PatchBoomboxItem));
		}

		public void Patch_Misc()
		{
			BindConfig(ref sfx_Player, "Misc", "Player");
			BindConfig(ref sfx_Dropship, "Misc", "Ship");
			BindConfig(ref sfx_Ship, "Misc", "Speaker");
			BindConfig(ref sfx_SystemSounds, "Misc", "System Sounds");
			if (sfx_Dropship.Value)
			{
				PatchItemDropship.sfx_Music = LoadAssetFromBundle("dropship_music", "mp3");
				PatchItemDropship.sfx_MusicFar = LoadAssetFromBundle("dropship_music_far", "mp3");
				LogInfo("New entry : Dropship SFX");
			}
			if (sfx_Ship.Value)
			{
				PatchStartOfRound.sfx_ShipIntroSpeaker = LoadAssetFromBundle("ship_speaker_intro");
				PatchStartOfRound.sfx_ShipZeroDaysSpeaker = LoadAssetFromBundle("ship_speaker_zerodaysleft");
				LogInfo("New entry : Ship SFX");
			}
			if (sfx_Player.Value)
			{
				PatchStartOfRound.sfx_PlayerFallDeath = LoadAssetFromBundle("player_falldeath");
				PatchStartOfRound.sfx_PlayerSuitChange = LoadAssetFromBundle("player_suitchange");
				LogInfo("New entry : Player SFX");
			}
			if (sfx_SystemSounds.Value)
			{
				PatchStartOfRound.sfx_PlayerPartyWipe = LoadAssetFromBundle("system_partywipe");
				PatchHUDManager.sfx_QuotaNewProfit = LoadAssetFromBundle("system_quota_new");
				PatchHUDManager.sfx_QuotaDaysLeft = LoadAssetFromBundle("system_quota_remaining");
				PatchHUDManager.sfx_QuotaOneDayLeft = LoadAssetFromBundle("system_quota_one_remaining");
				PatchHUDManager.sfx_QuotaReached = LoadAssetFromBundle("system_quota_reached");
				Patch_DepositItemsDesk.sfx_Reward = LoadAssetFromBundle("system_selling");
				LogInfo("New entry : System SFX");
			}
			harmony.PatchAll(typeof(PatchItemDropship));
			harmony.PatchAll(typeof(PatchStartOfRound));
			harmony.PatchAll(typeof(PatchHUDManager));
		}

		public static void LogInfo(object info)
		{
			MLS.LogInfo(info);
		}

		public static void LogWarning(object warning)
		{
			MLS.LogWarning(warning);
		}

		public static void LogError(object error)
		{
			MLS.LogError(error);
		}

		public void BindConfig(ref ConfigEntry<bool> config, string section, string key, bool defaultValue = true)
		{
			config = ((BaseUnityPlugin)this).Config.Bind<bool>(section, key, defaultValue, "Replaces " + key.ToLower() + "'s SFX.");
		}

		public static AudioClip LoadAssetFromBundle(string item, string format = "wav")
		{
			return ModBundle.LoadAssetWithSubAssets<AudioClip>("assets/ffxivsfx/" + item + "." + format)[0];
		}
	}
}
namespace FFXIVSFX.Patches
{
	[HarmonyPatch(typeof(DepositItemsDesk))]
	internal class Patch_DepositItemsDesk
	{
		internal static AudioClip sfx_Reward;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(DepositItemsDesk __instance)
		{
			if ((Object)(object)sfx_Reward != (Object)null)
			{
				__instance.rewardGood = sfx_Reward;
				__instance.rewardBad = sfx_Reward;
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal class PatchHoarderBugAI
	{
		internal static AudioClip sfx_Chitter;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(HoarderBugAI __instance)
		{
			if ((Object)(object)sfx_Chitter != (Object)null)
			{
				__instance.chitterSFX[0] = sfx_Chitter;
			}
		}
	}
	[HarmonyPatch(typeof(BoomboxItem))]
	internal class PatchBoomboxItem
	{
		internal static List<AudioClip> sfx_Musics;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(BoomboxItem __instance)
		{
			if (sfx_Musics != null && sfx_Musics.Count > 0)
			{
				__instance.musicAudios = sfx_Musics.ToArray();
			}
		}
	}
	[HarmonyPatch(typeof(ItemDropship))]
	internal class PatchItemDropship
	{
		internal static AudioClip sfx_Music;

		internal static AudioClip sfx_MusicFar;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(ItemDropship __instance)
		{
			if ((Object)(object)sfx_Music != (Object)null)
			{
				Transform val = ((Component)__instance).gameObject.transform.Find("Music");
				Transform val2 = ((Component)val).transform.Find("Music (1)");
				((Component)val).GetComponent<AudioSource>().clip = sfx_Music;
				((Component)val2).GetComponent<AudioSource>().clip = sfx_MusicFar;
			}
		}
	}
	[HarmonyPatch(typeof(GiftBoxItem))]
	internal class PatchGiftBoxItem
	{
		internal static AudioClip sfx_OpenGift;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(GiftBoxItem __instance)
		{
			if ((Object)(object)sfx_OpenGift != (Object)null)
			{
				__instance.openGiftAudio = sfx_OpenGift;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class PatchStartOfRound
	{
		internal static AudioClip sfx_ShipIntroSpeaker;

		internal static AudioClip sfx_ShipZeroDaysSpeaker;

		internal static AudioClip sfx_PlayerFallDeath;

		internal static AudioClip sfx_PlayerPartyWipe;

		internal static AudioClip sfx_PlayerSuitChange;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(StartOfRound __instance)
		{
			if ((Object)(object)sfx_ShipIntroSpeaker != (Object)null)
			{
				__instance.shipIntroSpeechSFX = sfx_ShipIntroSpeaker;
			}
			if ((Object)(object)sfx_ShipZeroDaysSpeaker != (Object)null)
			{
				__instance.zeroDaysLeftAlertSFX = sfx_ShipZeroDaysSpeaker;
			}
			if ((Object)(object)sfx_PlayerFallDeath != (Object)null)
			{
				__instance.playerFallDeath = sfx_PlayerFallDeath;
			}
			if ((Object)(object)sfx_PlayerPartyWipe != (Object)null)
			{
				__instance.allPlayersDeadAudio = sfx_PlayerPartyWipe;
			}
			if ((Object)(object)sfx_PlayerSuitChange != (Object)null)
			{
				__instance.changeSuitSFX = sfx_PlayerSuitChange;
			}
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal class PatchJesterAI
	{
		internal static AudioClip sfx_PopUp;

		internal static AudioClip sfx_Winding;

		internal static AudioClip sfx_Screaming;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Patch(JesterAI __instance)
		{
			if ((Object)(object)sfx_PopUp != (Object)null)
			{
				__instance.popUpSFX = sfx_PopUp;
			}
			if ((Object)(object)sfx_Winding != (Object)null)
			{
				__instance.popGoesTheWeaselTheme = sfx_Winding;
				Plugin.LogInfo(__instance.popUpTimer);
			}
			if ((Object)(object)sfx_Screaming != (Object)null)
			{
				__instance.screamingSFX = sfx_Screaming;
			}
		}

		[HarmonyPatch("SetJesterInitialValues")]
		[HarmonyPostfix]
		public static void JestAIInitialPatch(ref float ___popUpTimer)
		{
			if ((Object)(object)sfx_Winding != (Object)null)
			{
				___popUpTimer = 39.5f;
			}
		}
	}
	[HarmonyPatch(typeof(RadMechAI))]
	internal class PatchRadMechAI
	{
		internal static List<AudioClip> sfx_Creature;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(RadMechAI __instance)
		{
			if (sfx_Creature != null && sfx_Creature.Count > 0)
			{
				AudioClip[] array = (AudioClip[])(object)new AudioClip[4 + sfx_Creature.Count];
				for (int i = 0; i < 4; i++)
				{
					array[i] = ((EnemyAI)__instance).enemyType.audioClips[i];
				}
				for (int j = 0; j < sfx_Creature.Count; j++)
				{
					array[4 + j] = sfx_Creature[j];
				}
				((EnemyAI)__instance).enemyType.audioClips = array;
			}
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	internal class PatchFlowermanAI
	{
		internal static AudioClip sfx_Anger;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(FlowermanAI __instance)
		{
			if ((Object)(object)sfx_Anger != (Object)null)
			{
				__instance.creatureAngerVoice.clip = sfx_Anger;
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class PatchHUDManager
	{
		internal static AudioClip sfx_QuotaNewProfit;

		internal static AudioClip sfx_QuotaOneDayLeft;

		internal static AudioClip sfx_QuotaDaysLeft;

		internal static AudioClip sfx_QuotaReached;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(HUDManager __instance)
		{
			if ((Object)(object)sfx_QuotaNewProfit != (Object)null)
			{
				__instance.newProfitQuotaSFX = sfx_QuotaNewProfit;
			}
			if ((Object)(object)sfx_QuotaOneDayLeft != (Object)null)
			{
				__instance.OneDayToMeetQuotaSFX = sfx_QuotaOneDayLeft;
			}
			if ((Object)(object)sfx_QuotaDaysLeft != (Object)null)
			{
				__instance.profitQuotaDaysLeftCalmSFX = sfx_QuotaDaysLeft;
			}
			if ((Object)(object)sfx_QuotaReached != (Object)null)
			{
				__instance.reachedQuotaSFX = sfx_QuotaReached;
			}
		}
	}
	[HarmonyPatch(typeof(NoisemakerProp))]
	internal class PatchNoisemakerProp
	{
		internal static NoiseMakerPackage sfx_Airhorn;

		internal static NoiseMakerPackage sfx_Clownhorn;

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Patch(NoisemakerProp __instance)
		{
			if (((Object)((GrabbableObject)__instance).itemProperties).name == "Airhorn")
			{
				if (sfx_Airhorn == null)
				{
					return;
				}
				((GrabbableObject)__instance).useCooldown = sfx_Airhorn.ClipDuration;
				__instance.noiseSFX[0] = sfx_Airhorn.RegularClip;
				__instance.noiseSFXFar[0] = sfx_Airhorn.FarClip;
			}
			if (((Object)((GrabbableObject)__instance).itemProperties).name == "ClownHorn" && sfx_Clownhorn != null)
			{
				((GrabbableObject)__instance).useCooldown = sfx_Clownhorn.ClipDuration;
				__instance.noiseSFX[0] = sfx_Clownhorn.RegularClip;
				__instance.noiseSFXFar[0] = sfx_Clownhorn.FarClip;
				__instance.minPitch = 1f;
				__instance.maxPitch = 1f;
			}
		}
	}
	public class NoiseMakerPackage
	{
		public float ClipDuration;

		public AudioClip RegularClip;

		public AudioClip FarClip;

		public NoiseMakerPackage(string item)
		{
			RegularClip = Plugin.LoadAssetFromBundle(item);
			FarClip = Plugin.LoadAssetFromBundle(item + "_far");
			ClipDuration = RegularClip.length + 0.1f;
		}
	}
}