Decompiled source of GobblesVoice v1.1.2

GobbleVoice.dll

Decompiled 8 months ago
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 GobblesVoiceMod;
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("GobbleVoice")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GobbleVoice")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("31b7c006-bfef-4629-a771-025094d54c0a")]
[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")]
[HarmonyPatch(typeof(CentipedeAI))]
internal class CentipedePatch
{
	[HarmonyPatch("fallFromCeiling")]
	[HarmonyPrefix]
	public static void CentipedeAudioPatch(CentipedeAI __instance)
	{
		AudioClip screamAudioClip = GobbleVoiceBase.screamAudioClip;
		((EnemyAI)__instance).creatureSFX.PlayOneShot(screamAudioClip);
	}
}
[HarmonyPatch(typeof(HoarderBugAI))]
internal class HoarderBugPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void HoarderBugAudioPatch(ref AudioClip[] ___chitterSFX, ref AudioClip[] ___angryVoiceSFX, ref AudioClip[] ___angryScreechSFX)
	{
		___chitterSFX = GobbleVoiceBase.voiceLines;
		___angryVoiceSFX = (AudioClip[])(object)new AudioClip[1] { GobbleVoiceBase.angryVoiceClip };
		___angryScreechSFX = (AudioClip[])(object)new AudioClip[1] { GobbleVoiceBase.angryVoiceClip };
	}
}
namespace GobblesVoiceMod;

[BepInPlugin("Gobbles", "Gobbles Voice", "1.1.2")]
public class GobbleVoiceBase : BaseUnityPlugin
{
	private const string modGUID = "Gobbles";

	private const string modName = "Gobbles Voice";

	private const string modVersion = "1.1.2";

	private static GobbleVoiceBase Instance;

	private Harmony harmony;

	internal ManualLogSource mls;

	internal static AudioClip[] voiceLines;

	internal static AssetBundle assetBundle;

	internal static AudioClip screamAudioClip;

	internal static AudioClip angryVoiceClip;

	private void Awake()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = Logger.CreateLogSource("Gobbles");
		mls.LogInfo((object)"Plugin Gobbles.GobblesVoice is loaded!");
		Debug.Log((object)"GobbleVoiceBase Awake method is called!");
		harmony = new Harmony("Gobbles");
		harmony.PatchAll(typeof(GobbleVoiceBase));
		harmony.PatchAll(typeof(HoarderBugPatch));
		harmony.PatchAll(typeof(CentipedePatch));
		LoadVoiceLines();
	}

	private void LoadVoiceLines()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		Debug.Log((object)"LoadVoiceLines method is called!");
		GameObject val = new GameObject("AudioObjects");
		AudioSource val2 = val.AddComponent<AudioSource>();
		AudioSource val3 = val.AddComponent<AudioSource>();
		AudioSource val4 = val.AddComponent<AudioSource>();
		assetBundle = LoadAssetBundle("voicelines");
		if ((Object)(object)assetBundle != (Object)null)
		{
			voiceLines = (AudioClip[])(object)new AudioClip[20];
			for (int i = 0; i < voiceLines.Length; i++)
			{
				string text = $"voice{i + 1}";
				voiceLines[i] = assetBundle.LoadAsset<AudioClip>(text);
				if ((Object)(object)voiceLines[i] == (Object)null)
				{
					mls.LogError((object)("Failed to load audio clip: " + text));
				}
				else
				{
					mls.LogInfo((object)("Loaded audio clip: " + text));
				}
			}
			val2.clip = GetRandomVoiceLine();
			val2.Play();
		}
		else
		{
			mls.LogError((object)"Failed to load voice bundle!");
		}
		AssetBundle val5 = LoadAssetBundle("angrylaugh");
		if ((Object)(object)val5 != (Object)null)
		{
			angryVoiceClip = val5.LoadAsset<AudioClip>("laugh");
			if ((Object)(object)angryVoiceClip == (Object)null)
			{
				mls.LogError((object)"Failed to load angry voice clip from angrylaugh bundle!");
			}
			else
			{
				mls.LogInfo((object)"Loaded angry voice clip from angrylaugh bundle!");
				val3.clip = angryVoiceClip;
				val3.Play();
			}
		}
		else
		{
			mls.LogError((object)"Failed to load angrylaugh bundle!");
		}
		AssetBundle val6 = LoadAssetBundle("screamaudio");
		if ((Object)(object)val6 != (Object)null)
		{
			screamAudioClip = val6.LoadAsset<AudioClip>("scream_sound");
			if ((Object)(object)screamAudioClip == (Object)null)
			{
				mls.LogError((object)"Failed to load scream voice clip from screamaudio bundle!");
				return;
			}
			mls.LogInfo((object)"Loaded scream voice clip from screamaudio bundle!");
			val4.clip = screamAudioClip;
			val4.Play();
		}
		else
		{
			mls.LogError((object)"Failed to load screamaudio bundle!");
		}
	}

	internal static AudioClip GetRandomVoiceLine()
	{
		return voiceLines[Random.Range(0, voiceLines.Length)];
	}

	private AssetBundle LoadAssetBundle(string bundleName)
	{
		string pluginPath = Paths.PluginPath;
		string path = "Gobbles".Replace(".", "-") + "-GobblesVoice";
		string path2 = Path.Combine(pluginPath, path, bundleName);
		string fullPath = Path.GetFullPath(path2);
		AssetBundle val = AssetBundle.LoadFromFile(fullPath);
		if ((Object)(object)val == (Object)null)
		{
			mls.LogError((object)("Failed to load AssetBundle: " + fullPath));
		}
		else
		{
			mls.LogInfo((object)("Loaded AssetBundle: " + fullPath));
		}
		return val;
	}
}