Decompiled source of CaptainAutoShotgun Reloaded v2.0.0

plugins/CaptainAutoShotgun/CaptainAutoShotgun.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Captain.Weapon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.UI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 CaptainAutoShotgun
{
	public enum FireMode
	{
		FullCharge,
		MinimumCharge,
		CustomPercent
	}
	[BepInPlugin("com.reloaded.CaptainAutoShotgun", "CaptainAutoShotgun Reloaded", "2.0.0")]
	public class CaptainAutoShotgunPlugin : BaseUnityPlugin
	{
		public const string GUID = "com.reloaded.CaptainAutoShotgun";

		public const string NAME = "CaptainAutoShotgun Reloaded";

		public const string VERSION = "2.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<FireMode> Mode;

		internal static ConfigEntry<float> ChargePercent;

		internal static ConfigEntry<KeyboardShortcut> ToggleKey;

		internal static ConfigEntry<bool> ShowChatMessages;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Включить автоматическую стрельбу дробовика Капитана.\nEnable Captain's shotgun auto-fire.");
			Mode = ((BaseUnityPlugin)this).Config.Bind<FireMode>("General", "FireMode", FireMode.FullCharge, "Когда стрелять / When to fire:\nFullCharge - при полном заряде (кучный выстрел) / at full charge (tight spread)\nMinimumCharge - как можно быстрее / as fast as possible\nCustomPercent - при проценте из ChargePercent / at ChargePercent");
			ChargePercent = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChargePercent", 0.75f, new ConfigDescription("Процент заряда для режима CustomPercent (0.0 - 1.0).\nCharge fraction for CustomPercent mode (0.0 - 1.0).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "ToggleKey", new KeyboardShortcut((KeyCode)288, Array.Empty<KeyCode>()), "Клавиша включения/выключения автострельбы.\nKey to toggle auto-fire on/off.");
			ShowChatMessages = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "ShowChatMessages", true, "Показывать сообщение в чате при переключении.\nShow a chat message when toggling.");
			Language.collectLanguageRootFolders += AddLanguageFolder;
			_harmony = new Harmony("com.reloaded.CaptainAutoShotgun");
			_harmony.PatchAll(typeof(ChargeCaptainShotgunPatch));
			Log.LogInfo((object)"CaptainAutoShotgun Reloaded 2.0.0 loaded.");
		}

		private void AddLanguageFolder(List<string> folders)
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Language");
			if (Directory.Exists(text))
			{
				folders.Add(text);
			}
			else
			{
				Log.LogWarning((object)("Language folder not found: " + text));
			}
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = ToggleKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && !IsTypingInChat())
			{
				Enabled.Value = !Enabled.Value;
				if (ShowChatMessages.Value)
				{
					Chat.AddMessage(Language.GetString(Enabled.Value ? "CAPTAINAUTOSHOTGUN_ENABLED" : "CAPTAINAUTOSHOTGUN_DISABLED"));
				}
			}
		}

		private static bool IsTypingInChat()
		{
			try
			{
				ChatBox[] array = Object.FindObjectsOfType<ChatBox>();
				foreach (ChatBox val in array)
				{
					if (Object.op_Implicit((Object)(object)val) && val.showInput)
					{
						return true;
					}
				}
			}
			catch (Exception)
			{
			}
			return false;
		}

		private void OnDestroy()
		{
			Language.collectLanguageRootFolders -= AddLanguageFolder;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(ChargeCaptainShotgun), "FixedUpdate")]
	internal static class ChargeCaptainShotgunPatch
	{
		[HarmonyPrefix]
		private static void Prefix(ChargeCaptainShotgun __instance)
		{
			if (!CaptainAutoShotgunPlugin.Enabled.Value || !((EntityState)__instance).isAuthority)
			{
				return;
			}
			CharacterBody characterBody = ((EntityState)__instance).characterBody;
			if (Object.op_Implicit((Object)(object)characterBody) && characterBody.isPlayerControlled && !__instance.released)
			{
				float num = CaptainAutoShotgunPlugin.Mode.Value switch
				{
					FireMode.MinimumCharge => __instance.minChargeDuration, 
					FireMode.CustomPercent => Mathf.Max(__instance.minChargeDuration, __instance.chargeDuration * CaptainAutoShotgunPlugin.ChargePercent.Value), 
					_ => __instance.chargeDuration, 
				};
				if (((EntityState)__instance).fixedAge >= num)
				{
					__instance.released = true;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}