Decompiled source of jakiessoundsy v1.0.2

BepInEx/plugins/CustomSounds/Jakiessoundy/LethalClunk/LethalClunk.dll

Decompiled 9 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalClunk")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod to replace the Large Axle drop sound with the metal bar meme sound")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+32ab32b67da71ea7b44296192ba03dfcf26f159a")]
[assembly: AssemblyProduct("LethalClunk")]
[assembly: AssemblyTitle("LethalClunk")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class ExtensionMethods
{
	public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)
	{
		TaskCompletionSource<object?> tcs = new TaskCompletionSource<object>();
		asyncOp.completed += delegate
		{
			tcs.SetResult(null);
		};
		return ((Task)tcs.Task).GetAwaiter();
	}
}
namespace LethalClunk
{
	[BepInPlugin("LethalClunk", "LethalClunk", "1.1.1")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("LethalClunk");

		private readonly ManualLogSource logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			logger = Logger.CreateLogSource("LethalClunk");
		}

		public void Awake()
		{
			harmony.PatchAll();
			logger.LogInfo((object)"Plugin LethalClunk is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalClunk";

		public const string PLUGIN_NAME = "LethalClunk";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace LethalClunk.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class LethalClunkPatch
	{
		private static ManualLogSource logger = Logger.CreateLogSource("LethalClunk");

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static async void ReplaceLargeAxleSFX(GrabbableObject __instance)
		{
			Item item = __instance.itemProperties;
			AudioClip audioClip = await LoadAudioClip("metal_bar.wav");
			if (item.itemName == "Large axle")
			{
				logger.LogInfo((object)"Large Axle Spawned");
				if ((Object)(object)audioClip != (Object)null)
				{
					item.dropSFX = audioClip;
				}
			}
		}

		private static async Task<AudioClip?> LoadAudioClip(string clipName)
		{
			string fullPath = GetAssemblyFullPath(clipName);
			UnityWebRequest audioClipReq = UnityWebRequestMultimedia.GetAudioClip(fullPath, (AudioType)20);
			await (AsyncOperation)(object)audioClipReq.SendWebRequest();
			if (audioClipReq.error != null)
			{
				logger.LogError((object)audioClipReq.error);
				logger.LogError((object)"Failed to load audio clip for LethalClunk, sound will not be replaced");
				return null;
			}
			AudioClip audioClip = DownloadHandlerAudioClip.GetContent(audioClipReq);
			((Object)audioClip).name = Path.GetFileName(fullPath);
			return audioClip;
		}

		private static string GetAssemblyFullPath(string? additionalPath)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = ((additionalPath != null) ? Path.Combine(directoryName, ".\\" + additionalPath) : directoryName);
			return Path.GetFullPath(path);
		}
	}
}