Decompiled source of BoltPumpQuickShooter v1.1.0

Niko666.BoltPumpQuickShooter.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
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("Force enable quickbolt for bolt-actions and slam-fire for pump-actions.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("Niko666.BoltPumpQuickShooter")]
[assembly: AssemblyTitle("BoltPumpQuickShooter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 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.BoltPumpQuickShooter", "BoltPumpQuickShooter", "1.1.0")]
	public class BoltPumpQuickShooter : BaseUnityPlugin
	{
		public static ConfigEntry<bool> configEnableSlamfire;

		public static ConfigEntry<bool> configEnableQuickbolt;

		public static ConfigEntry<bool> configForceSlamfireInSemiAutoMode;

		public const string Id = "Niko666.BoltPumpQuickShooter";

		public static BoltPumpQuickShooter Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public static string Name => "BoltPumpQuickShooter";

		public static string Version => "1.1.0";

		public void Awake()
		{
			Instance = this;
			configEnableSlamfire = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableSlamfire", true, "Force enable slamfire for all pump-action shotguns");
			configEnableQuickbolt = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableQuickbolt", true, "Force enable quickbolt for all bolt-action rifles");
			configForceSlamfireInSemiAutoMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ForceSlamfireInSemiAutoMode", false, "Force slamfire in semi-auto tubefed shotguns, essentially making them full-auto. Otherwise leave it as is so tube-fed shotguns with full-auto selector (e.g. Remington 7188) can still work as is.");
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(BoltPumpQuickShooterPatch), (string)null);
			Logger.LogMessage((object)("Fuck this world! Sent from Niko666.BoltPumpQuickShooter " + Version));
		}
	}
	public class BoltPumpQuickShooterPatch : MonoBehaviour
	{
		private static readonly Dictionary<TubeFedShotgun, bool> OriginalSlamfireSettings = new Dictionary<TubeFedShotgun, bool>();

		[HarmonyPatch(typeof(SteamVR_LoadLevel), "Begin")]
		[HarmonyPrefix]
		public static bool BeginPatch()
		{
			((BaseUnityPlugin)BoltPumpQuickShooter.Instance).Config.Reload();
			OriginalSlamfireSettings.Clear();
			return true;
		}

		[HarmonyPatch(typeof(BoltActionRifle_Handle), "Awake")]
		[HarmonyPostfix]
		public static void BoltActionRifle_ForceQuickbolt(BoltActionRifle_Handle __instance)
		{
			if (BoltPumpQuickShooter.configEnableQuickbolt.Value && !__instance.UsesQuickRelease)
			{
				__instance.UsesQuickRelease = true;
			}
		}

		[HarmonyPatch(typeof(TubeFedShotgun), "FVRUpdate")]
		[HarmonyPostfix]
		public static void TubeFedShotgun_ForceSlamfire(TubeFedShotgun __instance)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!OriginalSlamfireSettings.ContainsKey(__instance))
			{
				OriginalSlamfireSettings[__instance] = __instance.UsesSlamFireTrigger;
			}
			bool flag = OriginalSlamfireSettings[__instance];
			if (BoltPumpQuickShooter.configEnableSlamfire.Value)
			{
				if ((int)__instance.Mode == 1)
				{
					if (BoltPumpQuickShooter.configForceSlamfireInSemiAutoMode.Value)
					{
						__instance.UsesSlamFireTrigger = true;
					}
					else if (!flag)
					{
						OriginalSlamfireSettings[__instance] = __instance.UsesSlamFireTrigger;
						__instance.UsesSlamFireTrigger = flag;
					}
				}
				else if ((int)__instance.Mode == 0)
				{
					__instance.UsesSlamFireTrigger = true;
				}
				else
				{
					__instance.UsesSlamFireTrigger = flag;
				}
			}
			else
			{
				__instance.UsesSlamFireTrigger = flag;
			}
		}
	}
}