Decompiled source of Fish Meme SFX Replacement v1.0.1

BepInEx/plugins/FISH Mod.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FISH Mod.NetcodePatcher;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FISH Mod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FISH Mod")]
[assembly: AssemblyTitle("FISH Mod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace FISH_Mod
{
	[BepInPlugin("koolkids.fish", "FISH!!!", "1.0.1")]
	public class FishSFXReplacement : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <LoadFishSFXFromBundle>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public FishSFXReplacement <>4__this;

			private string <pluginFolder>5__1;

			private string <bundlePath>5__2;

			private AssetBundle <bundle>5__3;

			private AudioClip <clip>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadFishSFXFromBundle>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<pluginFolder>5__1 = null;
				<bundlePath>5__2 = null;
				<bundle>5__3 = null;
				<clip>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<pluginFolder>5__1 = Path.GetDirectoryName(typeof(FishSFXReplacement).Assembly.Location);
					<bundlePath>5__2 = Path.Combine(<pluginFolder>5__1, "fishsfxbundle");
					if (!File.Exists(<bundlePath>5__2))
					{
						if (EnableDebugLogs)
						{
							Logger.LogError((object)"[FISH!!!] Failed to load AssetBundle from any of the possible paths.");
						}
						return false;
					}
					<bundle>5__3 = AssetBundle.LoadFromFile(<bundlePath>5__2);
					if ((Object)(object)<bundle>5__3 == (Object)null)
					{
						if (EnableDebugLogs)
						{
							Logger.LogError((object)"[FISH!!!] Failed to load AssetBundle!");
						}
						return false;
					}
					<clip>5__4 = <bundle>5__3.LoadAsset<AudioClip>("meme_fish_sfx");
					if ((Object)(object)<clip>5__4 == (Object)null)
					{
						if (EnableDebugLogs)
						{
							Logger.LogError((object)"[FISH!!!] Failed to load 'meme_fish_sfx' from AssetBundle!");
						}
						<bundle>5__3.Unload(false);
						return false;
					}
					fishSFX = <clip>5__4;
					if (EnableDebugLogs)
					{
						Logger.LogInfo((object)"[FISH!!!] Successfully loaded 'meme_fish_sfx' from AssetBundle.");
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static AudioClip? fishSFX;

		public static ConfigEntry<bool>? EnableDebugLogsConfig;

		public static FishSFXReplacement Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public static bool EnableDebugLogs => EnableDebugLogsConfig?.Value ?? false;

		private void Awake()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			EnableDebugLogsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableDebugLogs", false, "Enable debug logs for FISH!!! mod");
			if (EnableDebugLogs)
			{
				Logger.LogInfo((object)"[FISH!!!] Plugin awake, loading AssetBundle...");
			}
			if (EnableDebugLogs)
			{
				Logger.LogInfo((object)"Plugin successfully loaded with debug logs enabled.");
			}
			else
			{
				Logger.LogInfo((object)"FISH!!! mod loaded.");
			}
			((MonoBehaviour)this).StartCoroutine(LoadFishSFXFromBundle());
			Harmony val = new Harmony("koolkids.fish");
			val.PatchAll();
			if (EnableDebugLogs)
			{
				Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			}
		}

		[IteratorStateMachine(typeof(<LoadFishSFXFromBundle>d__13))]
		private IEnumerator LoadFishSFXFromBundle()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadFishSFXFromBundle>d__13(0)
			{
				<>4__this = this
			};
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "GrabItem")]
	public static class GrabbableObject_GrabItem_Patch
	{
		private static void Postfix(GrabbableObject __instance)
		{
			if ((Object)(object)__instance == (Object)null || !((Object)__instance).name.Contains("FishTestProp"))
			{
				return;
			}
			if (FishSFXReplacement.EnableDebugLogs)
			{
				FishSFXReplacement.Logger.LogInfo((object)"[FISH!!!] Playing fish meme sound on grabbed object.");
			}
			if ((Object)(object)FishSFXReplacement.fishSFX == (Object)null)
			{
				if (FishSFXReplacement.EnableDebugLogs)
				{
					FishSFXReplacement.Logger.LogWarning((object)"[FISH!!!] AudioClip is null, cannot play sound.");
				}
			}
			else
			{
				AudioSource val = ((Component)__instance).GetComponent<AudioSource>() ?? ((Component)__instance).gameObject.AddComponent<AudioSource>();
				val.clip = FishSFXReplacement.fishSFX;
				val.volume = 0.8f;
				val.spatialBlend = 1f;
				val.Play();
			}
		}
	}
}
namespace FISH Mod.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}