Decompiled source of LethalRichie v1.0.1

LethalRichie.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using LethalRichie.Patches;
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("LethalRichie")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalRichie")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6bf07c61-4c74-460e-8a1d-b7be46af7d7b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalRichie
{
	[BepInPlugin("KaosRichie.LethalRichiePlugin", "Lethal Richie", "1.0.0")]
	public class LethalRichiePlugin : BaseUnityPlugin
	{
		private const string modGUID = "KaosRichie.LethalRichiePlugin";

		private const string modName = "Lethal Richie";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("KaosRichie.LethalRichiePlugin");

		public AssetBundle lethalRichieAssetBundle;

		private const string assetBundleName = "lethalrichie";

		public GameObject customAudioSourceGO;

		public AudioSource customAudioSource;

		public AudioClip ShipLeaveAudioClip;

		public static LethalRichiePlugin Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Lethal Richie loaded");
			LoadAssetBundle();
			ShipLeaveAudioClip = lethalRichieAssetBundle.LoadAsset<AudioClip>("SPECIALZ.wav");
			if ((Object)(object)ShipLeaveAudioClip == (Object)null)
			{
				Debug.LogError((object)"[LethalRichie] Failed to load audio clip");
			}
			harmony.PatchAll(typeof(StartOfRoundPatch));
		}

		public void PlayShipLeaveAudio()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			if ((Object)(object)customAudioSourceGO == (Object)null)
			{
				customAudioSourceGO = new GameObject("LethalRichie Custom Audio Source", new Type[1] { typeof(AudioSource) });
				Object.DontDestroyOnLoad((Object)(object)customAudioSourceGO);
				customAudioSource = customAudioSourceGO.GetComponent<AudioSource>();
				if ((Object)(object)customAudioSource == (Object)null)
				{
					Debug.LogError((object)"[LethalRichie] Failed to create custom audio source");
				}
				customAudioSource.playOnAwake = false;
			}
			customAudioSource.PlayOneShot(ShipLeaveAudioClip);
		}

		private void LoadAssetBundle()
		{
			string location = ((BaseUnityPlugin)this).Info.Location;
			location = location.TrimEnd("LethalRichiePlugin.dll".ToCharArray());
			lethalRichieAssetBundle = AssetBundle.LoadFromFile(location + "lethalrichie");
			if ((Object)(object)lethalRichieAssetBundle == (Object)null)
			{
				Debug.LogError((object)"[LethalRichie] Could not load assetbundle: lethalrichie");
			}
		}
	}
}
namespace LethalRichie.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("ShipLeave")]
		[HarmonyPrefix]
		private static void ShipLeavePatch(StartOfRound __instance)
		{
			if (__instance.allPlayersDead)
			{
				LethalRichiePlugin.Instance.PlayShipLeaveAudio();
			}
		}
	}
}