Decompiled source of Auto cleanup v1.0.0

auto_cleanup.dll

Decompiled a week 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("your_name")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Sample BepInEx plugin template for H3VR!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("auto_cleanup")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[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 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 plugin
{
	[BepInPlugin("Aiyke.Auto_cleanup", "Auto cleanup", "1.0.0")]
	[BepInProcess("h3vr.exe")]
	public class auto_cleanup : BaseUnityPlugin
	{
		public static ConfigEntry<float> interval;

		private static float cleanup_timer;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogMessage((object)"auto_cleanup active.");
			interval = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Cleanup interval (minutes)", 3f, "The amount of time, in minutes, between cleanups.");
			Harmony.CreateAndPatchAll(typeof(auto_cleanup), (string)null);
		}

		private void Update()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			cleanup_timer -= Time.deltaTime;
			if (!(cleanup_timer <= 0f))
			{
				return;
			}
			FVRFireArmMagazine[] array = Object.FindObjectsOfType<FVRFireArmMagazine>();
			for (int num = array.Length - 1; num >= 0; num--)
			{
				if (!((FVRInteractiveObject)array[num]).IsHeld && (Object)(object)((FVRPhysicalObject)array[num]).QuickbeltSlot == (Object)null && (Object)(object)array[num].FireArm == (Object)null && array[num].m_numRounds <= array[num].m_capacity / 2 && !array[num].IsIntegrated)
				{
					Object.Destroy((Object)(object)((Component)array[num]).gameObject);
				}
			}
			FVRFireArmClip[] array2 = Object.FindObjectsOfType<FVRFireArmClip>();
			for (int num2 = array2.Length - 1; num2 >= 0; num2--)
			{
				if (!((FVRInteractiveObject)array2[num2]).IsHeld && (Object)(object)((FVRPhysicalObject)array2[num2]).QuickbeltSlot == (Object)null && (Object)(object)array2[num2].FireArm == (Object)null && array2[num2].m_numRounds <= array2[num2].m_capacity / 2)
				{
					Object.Destroy((Object)(object)((Component)array2[num2]).gameObject);
				}
			}
			int num3 = 0;
			Speedloader[] array3 = Object.FindObjectsOfType<Speedloader>();
			for (int num4 = array3.Length - 1; num4 >= 0; num4--)
			{
				if (!((FVRInteractiveObject)array3[num4]).IsHeld && (Object)(object)((FVRPhysicalObject)array3[num4]).QuickbeltSlot == (Object)null)
				{
					for (int i = 0; i < array3[num4].Chambers.Count; i++)
					{
						if (array3[num4].Chambers[i].IsLoaded)
						{
							num3++;
						}
					}
					if (num3 < array3[num4].Chambers.Count || num3 == 0)
					{
						Object.Destroy((Object)(object)((Component)array3[num4]).gameObject);
					}
				}
			}
			cleanup_timer = interval.Value * 60f;
		}
	}
}