Decompiled source of SaferDoomShotgun v0.0.1

SaferDoomShotgun.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LCSoundTool;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("SaferDoomShotgun")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Only play the music when the safety is off")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SaferDoomShotgun")]
[assembly: AssemblyTitle("SaferDoomShotgun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SaferDoomShotgun
{
	[BepInPlugin("SaferDoomShotgun", "SaferDoomShotgun", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ShotgunItem), "Start")]
		public static class ShotgunPatch
		{
			public static void Postfix(ShotgunItem __instance)
			{
				AudioSource val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
				val.clip = _doomMusic;
				val.loop = true;
				val.volume = _volume;
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "EquipItem")]
		public static class ShotgunEquipPatch
		{
			public static void Postfix(ShotgunItem __instance)
			{
				if (!__instance.safetyOn)
				{
					StartShotgunMusic(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "ItemInteractLeftRight")]
		public static class ShotgunInteractPatch
		{
			public static void Postfix(ShotgunItem __instance)
			{
				if (__instance.safetyOn)
				{
					StopShotgunMusic(__instance);
				}
				else
				{
					StartShotgunMusic(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "StopUsingGun")]
		public static class ShotgunStopPatch
		{
			public static void Postfix(ShotgunItem __instance)
			{
				StopShotgunMusic(__instance);
			}
		}

		private static AudioClip _doomMusic;

		private static ConfigEntry<float> _volumeC;

		private static float _volume;

		private void Awake()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SaferDoomShotgun is loaded.");
			_doomMusic = SoundTool.GetAudioClip("aRealHumanBean-SaferDoomShotgun", "doom.mp3");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Sound loaded");
			_volumeC = ((BaseUnityPlugin)this).Config.Bind<float>("General", "volume", 0.7f, "Set the volume of the music");
			_volume = _volumeC.Value;
			float volume = _volume;
			float num = volume;
			if (!(num > 1f))
			{
				if (num < 0f)
				{
					_volume = 0f;
				}
			}
			else
			{
				_volume = 1f;
			}
			Harmony val = new Harmony("SaferDoomShotgun");
			val.PatchAll();
		}

		private static void StopShotgunMusic(ShotgunItem shotgun)
		{
			Debug.Log((object)"Stopping shotgun music.");
			AudioSource val = ((Component)shotgun).gameObject.GetComponents<AudioSource>().First((AudioSource x) => (Object)(object)x.clip == (Object)(object)_doomMusic);
			val.Pause();
		}

		private static void StartShotgunMusic(ShotgunItem shotgun)
		{
			Debug.Log((object)"Starting shotgun music.");
			AudioSource val = ((Component)shotgun).gameObject.GetComponents<AudioSource>().First((AudioSource x) => (Object)(object)x.clip == (Object)(object)_doomMusic);
			if (!val.isPlaying)
			{
				val.Play();
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SaferDoomShotgun";

		public const string PLUGIN_NAME = "SaferDoomShotgun";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}