Decompiled source of BulletCatch v1.0.0

BulletCatch.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using HarmonyLib;
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("BulletCatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BulletCatch")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9FB99B0D-2F7F-426A-A05F-592AF5914A01")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BulletCatch;

[BepInPlugin("h3vr.kodeman.bulletcatch", "Bullet Catch", "1.0.0")]
[BepInProcess("h3vr.exe")]
public class BulletCatch : BaseUnityPlugin
{
	private static BulletCatch _instance;

	private static ConfigEntry<bool> EnableBulletCatch;

	private static ConfigEntry<float> BulletCatchRadius;

	private static ConfigEntry<float> BulletCatchTime;

	private static ConfigEntry<float> DelayBeforeBulletCatch;

	private void Start()
	{
		_instance = this;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		EnableBulletCatch = ((BaseUnityPlugin)this).Config.Bind<bool>("BulletCatch", "Enable Bullet Catch", true, "Allows for easier way to catch bullets when ejected.");
		BulletCatchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("BulletCatch", "Bullet Catch Radius", 0.125f, "How big the bullet catch radius is.");
		BulletCatchTime = ((BaseUnityPlugin)this).Config.Bind<float>("BulletCatch", "Bullet Catch Time", 0.75f, "How long the bullet catch lasts for.");
		DelayBeforeBulletCatch = ((BaseUnityPlugin)this).Config.Bind<float>("BulletCatch", "Delay Before Bullet Catch", 0.1f, "How long between bullet being ejected and the bullet catch being active.");
		Harmony.CreateAndPatchAll(typeof(BulletCatch), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Bullet catch mod loaded.");
	}

	[HarmonyPatch(typeof(FVRFireArmChamber), "EjectRound", new Type[]
	{
		typeof(Vector3),
		typeof(Vector3),
		typeof(Vector3),
		typeof(bool)
	})]
	[HarmonyPatch(typeof(FVRFireArmChamber), "EjectRound", new Type[]
	{
		typeof(Vector3),
		typeof(Vector3),
		typeof(Vector3),
		typeof(Vector3),
		typeof(Quaternion),
		typeof(bool)
	})]
	[HarmonyPostfix]
	public static void OnEjectRound(FVRFireArmChamber __instance, ref FVRFireArmRound __result)
	{
		if (EnableBulletCatch.Value && !((Object)(object)__result == (Object)null) && !__result.IsSpent)
		{
			((MonoBehaviour)_instance).StartCoroutine(DoTheCatchingCR(__result));
		}
	}

	private static IEnumerator DoTheCatchingCR(FVRFireArmRound __result)
	{
		yield return (object)new WaitForSeconds(DelayBeforeBulletCatch.Value);
		SphereCollider trigger = ((Component)__result).gameObject.AddComponent<SphereCollider>();
		((Collider)trigger).isTrigger = true;
		trigger.radius = BulletCatchRadius.Value;
		yield return (object)new WaitForSeconds(BulletCatchTime.Value);
		Object.Destroy((Object)(object)trigger);
	}
}