Decompiled source of SPAS12SwitchAnytime v1.0.0

Niko666.SPAS12SwitchAnytime.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Niko666")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows you to switch SPAS-12 (and other tube fed shotguns) firing mode at anytime, regardless of the hammer state.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Niko666.SPAS12SwitchAnytime")]
[assembly: AssemblyTitle("SPAS12SwitchAnytime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace Niko666
{
	[BepInProcess("h3vr.exe")]
	[BepInPlugin("Niko666.SPAS12SwitchAnytime", "SPAS12SwitchAnytime", "1.0.0")]
	public class SPAS12SwitchAnytime : BaseUnityPlugin
	{
		public static ConfigEntry<bool> configAllowBoltNotForward;

		public static ConfigEntry<bool> configAllowPumpNotForward;

		public static ConfigEntry<bool> configAllowHammerCocked;

		public const string Id = "Niko666.SPAS12SwitchAnytime";

		public static SPAS12SwitchAnytime Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public static string Name => "SPAS12SwitchAnytime";

		public static string Version => "1.0.0";

		private void Awake()
		{
			Instance = this;
			configAllowBoltNotForward = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowBoltNotForward", false, "Force enable mode switching when bolt is not forward");
			configAllowPumpNotForward = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowPumpNotForward", false, "Force enable mode switching when pump is not forward");
			configAllowHammerCocked = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowHammerCocked", true, "Force enable mode switching when hammer is cocked");
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogMessage((object)("Hello, world! Sent from Niko666.SPAS12SwitchAnytime " + Version));
			Harmony.CreateAndPatchAll(typeof(HarmonyPatches), (string)null);
		}
	}
	public class HarmonyPatches : MonoBehaviour
	{
		[HarmonyPatch(typeof(SteamVR_LoadLevel), "Begin")]
		[HarmonyPrefix]
		public static bool BeginPatch()
		{
			((BaseUnityPlugin)SPAS12SwitchAnytime.Instance).Config.Reload();
			return true;
		}

		[HarmonyPatch(typeof(TubeFedShotgun), "ToggleMode")]
		[HarmonyPrefix]
		private static bool ToggleMode_Prefix(TubeFedShotgun __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.Bolt.CurPos != 0 && !SPAS12SwitchAnytime.configAllowBoltNotForward.Value)
			{
				Debug.Log((object)"bolt not forward");
				return false;
			}
			if (__instance.HasHandle && (int)__instance.Handle.CurPos != 0 && !SPAS12SwitchAnytime.configAllowPumpNotForward.Value)
			{
				Debug.Log((object)"handle not forward");
				return false;
			}
			if (__instance.m_isHammerCocked && !SPAS12SwitchAnytime.configAllowHammerCocked.Value)
			{
				Debug.Log((object)"hammer cocked");
				return false;
			}
			((FVRFireArm)__instance).PlayAudioEvent((FirearmAudioEventType)15, 1f);
			if ((int)__instance.Mode == 0)
			{
				__instance.Mode = (ShotgunMode)1;
				if (__instance.HasHandle)
				{
					__instance.Handle.LockHandle();
				}
			}
			else
			{
				__instance.Mode = (ShotgunMode)0;
				if (__instance.HasHandle)
				{
					if ((Object)(object)__instance.Chamber != (Object)null && __instance.Chamber.IsFull)
					{
						return false;
					}
					__instance.Handle.UnlockHandle();
				}
			}
			return false;
		}
	}
}