Decompiled source of BetterSentryKeys v1.0.0

BetterSentryKeys.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using On;
using On.RoR2;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterSentryKeys")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterSentryKeys")]
[assembly: AssemblyTitle("BetterSentryKeys")]
[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 BetterSentryKeys
{
	[BepInPlugin("Bloonjitsu7.BetterSentryKeys", "BetterSentryKeys", "1.0.0")]
	public class BetterSentryKeysPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Bloonjitsu7.BetterSentryKeys";

		public const string PluginAuthor = "Bloonjitsu7";

		public const string PluginName = "BetterSentryKeys";

		public const string PluginVersion = "1.0.0";

		public static bool dropCooldown;

		public static ConfigEntry<bool> GuaranteedDrops { get; set; }

		public static ConfigEntry<float> DropCooldown { get; set; }

		public static ConfigEntry<bool> EnableStats { get; set; }

		public static ConfigEntry<float> StackedStats { get; set; }

		public static ConfigEntry<bool> ReusableShrines { get; set; }

		public static ConfigEntry<float> ShrineCooldown { get; set; }

		public void Awake()
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			GuaranteedDrops = ((BaseUnityPlugin)this).Config.Bind<bool>("Sentry Key Drops", "Enable Changes", true, "Causes collective elites to always drop sentry keys in Conduit Canyon. On by default.");
			DropCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Sentry Key Drops", "Cooldown Time", 1f, "Minimum amount of time (in seconds) between sentry key drops, to prevent potential item spam. Set to 0 for no cooldown.");
			EnableStats = ((BaseUnityPlugin)this).Config.Bind<bool>("Sentry Key Stats", "Enable Changes", false, "Allows the movement speed bonus from sentry keys to stack. Off by default.");
			StackedStats = ((BaseUnityPlugin)this).Config.Bind<float>("Sentry Key Stats", "Speed Stacking", 1.5f, "Movement speed bonus to gain for each additional sentry key. (100 = 100% bonus speed)");
			ReusableShrines = ((BaseUnityPlugin)this).Config.Bind<bool>("Collective Combat Shrines", "Enable Changes", false, "Allows the combat shrines on Conduit Canyon to be reused after a set duration. Off by default.");
			ShrineCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Collective Combat Shrines", "Cooldown Time", 90f, "Cooldown time (in seconds) before a combat shrine can be reused. Set to 0 for no cooldown.");
			if (EnableStats.Value)
			{
				RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(OnRecalcStats);
				LanguageAPI.AddOverlay("ITEM_POWERPYRAMID_DESC", $"Gain <style=cIsUtility>+15% move speed</style> <style=cStack>(+{StackedStats.Value}% per stack)</style>. Can be placed in a Sentry Terminal or used for decryption.");
			}
			if (GuaranteedDrops.Value)
			{
				PowerOrbKeySpawner.SpawnKey += new hook_SpawnKey(OnSpawnKey);
			}
			if (ReusableShrines.Value)
			{
				ShrineCombatTroopBehavior.AddShrineStack += new hook_AddShrineStack(OnShrineActivate);
				ShrineCombatTroopBehavior.FixedUpdate += new hook_FixedUpdate(OnShrineUpdate);
			}
		}

		private void OnRecalcStats(CharacterBody sender, StatHookEventArgs args)
		{
			if ((Object)(object)sender.inventory != (Object)null && sender.inventory.GetItemCountEffective(Items.PowerPyramid) > 0)
			{
				int num = sender.inventory.GetItemCountEffective(Items.PowerPyramid) - 1;
				args.moveSpeedMultAdd += (float)num * (StackedStats.Value / 100f);
			}
		}

		private void OnSpawnKey(orig_SpawnKey orig, PowerOrbKeySpawner self, DamageReport damageReport)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || (Object)(object)damageReport.victimBody.inventory == (Object)null || !damageReport.victimBody.inventory.HasEquipment(Equipment.EliteCollectiveEquipment.equipmentIndex))
			{
				return;
			}
			CharacterMaster master = damageReport.victimBody.master;
			if (!dropCooldown)
			{
				((MonoBehaviour)self).StartCoroutine(SentryKeyCooldown(DropCooldown.Value));
				Vector3 position = damageReport.victimBody.transform.position;
				IPhysMotor component = ((Component)damageReport.victimBody).GetComponent<IPhysMotor>();
				Quaternion rotation = damageReport.victimBody.transform.rotation;
				Vector3 val = Vector3.zero;
				if (Object.op_Implicit((Object)component))
				{
					val = component.velocity;
				}
				CreatePickupInfo val2 = default(CreatePickupInfo);
				((CreatePickupInfo)(ref val2)).pickupIndex = PickupCatalog.FindPickupIndex(Items.PowerPyramid.itemIndex);
				PickupDropletController.CreatePickupDroplet(val2, position, val);
			}
		}

		public IEnumerator SentryKeyCooldown(float delay)
		{
			dropCooldown = true;
			yield return (object)new WaitForSeconds(delay);
			dropCooldown = false;
		}

		private void OnShrineUpdate(orig_FixedUpdate orig, ShrineCombatTroopBehavior self)
		{
			orig.Invoke(self);
			if (NetworkServer.active && self.refreshTimer <= 0f && !((Component)self.symbolTransform).gameObject.activeInHierarchy)
			{
				((Component)self.symbolTransform).gameObject.SetActive(true);
			}
		}

		private void OnShrineActivate(orig_AddShrineStack orig, ShrineCombatTroopBehavior self, Interactor interactor)
		{
			self.maxPurchaseCount = 2;
			self.purchaseCount = 0;
			orig.Invoke(self, interactor);
			self.refreshTimer = ShrineCooldown.Value;
			((Component)self.symbolTransform).gameObject.SetActive(false);
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
}