Decompiled source of EnemyValuableTweaks v1.0.1

EnemyValuableTweaks.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("BLOKBUSTR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3caee8e87d7fb15beca53a7e8b77159e1e684154")]
[assembly: AssemblyProduct("EnemyValuableTweaks")]
[assembly: AssemblyTitle("EnemyValuableTweaks")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 EnemyValuableTweaks
{
	[HarmonyPatch(typeof(EnemyValuable))]
	internal static class EnemyValuablePatch
	{
		private static Dictionary<object, float> _orbAdditionalCheckDelay = new Dictionary<object, float>();

		private static Dictionary<object, float> _orbGrabTimers = new Dictionary<object, float>();

		private static Dictionary<object, float> _orbCartTimers = new Dictionary<object, float>();

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPostfix(EnemyValuable __instance)
		{
			EnemyValuableTweaks.Logger.LogInfo((object)$"New EnemyValuable has spawned ({((Object)__instance).GetInstanceID()})");
			__instance.indestructibleTimer = EnemyValuableTweaks.configTimerLength.Value;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdatePostfix(EnemyValuable __instance)
		{
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.indestructibleTimer < 0f)
			{
				MakeDestructible(__instance);
			}
			if (!__instance.impactDetector.destroyDisable)
			{
				return;
			}
			if (!EnemyValuableTweaks.configEnableTimer.Value)
			{
				__instance.indestructibleTimer = 60f;
			}
			else if (__instance.indestructibleTimer > 0f && EnemyValuableTweaks.configEnableDebugLogs.Value)
			{
				EnemyValuableTweaks.Logger.LogDebug((object)$"Time remaining: {__instance.indestructibleTimer}");
			}
			if (EnemyValuableTweaks.configAdditionalChecksDelay.Value > 0f)
			{
				if (!_orbAdditionalCheckDelay.ContainsKey(__instance))
				{
					_orbAdditionalCheckDelay[__instance] = EnemyValuableTweaks.configAdditionalChecksDelay.Value;
				}
				if (_orbAdditionalCheckDelay[__instance] > 0f)
				{
					_orbAdditionalCheckDelay[__instance] -= Time.deltaTime;
					if (EnemyValuableTweaks.configEnableDebugLogs.Value)
					{
						EnemyValuableTweaks.Logger.LogDebug((object)$"Delaying additional checks for: {_orbAdditionalCheckDelay[__instance]} ({((Object)__instance).GetInstanceID()})");
					}
					return;
				}
			}
			if (EnemyValuableTweaks.configEnableVelocityCheck.Value)
			{
				Vector3 velocity = __instance.impactDetector.rb.velocity;
				Vector3 previousVelocity = __instance.impactDetector.previousVelocity;
				float num = Mathf.Max(new float[6]
				{
					Mathf.Abs(velocity.x),
					Mathf.Abs(velocity.y),
					Mathf.Abs(velocity.z),
					Mathf.Abs(previousVelocity.x),
					Mathf.Abs(previousVelocity.y),
					Mathf.Abs(previousVelocity.z)
				});
				if (EnemyValuableTweaks.configEnableDebugLogs.Value)
				{
					EnemyValuableTweaks.Logger.LogDebug((object)$"curVel: {velocity} | prevVel: {previousVelocity} | combined: {num}");
				}
				if (num < EnemyValuableTweaks.configVelocityThreshold.Value)
				{
					MakeDestructible(__instance);
					return;
				}
			}
			if (EnemyValuableTweaks.configEnablePlayerHold.Value)
			{
				if (__instance.impactDetector.physGrabObject.playerGrabbing.Count > 0)
				{
					if (EnemyValuableTweaks.configPlayerHoldTime.Value == 0f)
					{
						MakeDestructible(__instance);
						return;
					}
					if (!_orbGrabTimers.ContainsKey(__instance))
					{
						_orbGrabTimers[__instance] = EnemyValuableTweaks.configPlayerHoldTime.Value;
						if (EnemyValuableTweaks.configEnableDebugLogs.Value)
						{
							EnemyValuableTweaks.Logger.LogDebug((object)$"Player grabbed ({((Object)__instance).GetInstanceID()})");
						}
					}
					HandleTimerDictionaries(_orbGrabTimers, __instance);
				}
				else if (_orbGrabTimers.Remove(__instance) && EnemyValuableTweaks.configEnableDebugLogs.Value)
				{
					EnemyValuableTweaks.Logger.LogDebug((object)$"Player let go ({((Object)__instance).GetInstanceID()})");
				}
			}
			if (!EnemyValuableTweaks.configEnableSafeAreaCheck.Value)
			{
				return;
			}
			if (__instance.impactDetector.inCart)
			{
				if (EnemyValuableTweaks.configSafeAreaTime.Value == 0f)
				{
					MakeDestructible(__instance);
					return;
				}
				if (!_orbCartTimers.ContainsKey(__instance))
				{
					_orbCartTimers[__instance] = EnemyValuableTweaks.configSafeAreaTime.Value;
					if (EnemyValuableTweaks.configEnableDebugLogs.Value)
					{
						EnemyValuableTweaks.Logger.LogDebug((object)$"Placed in safe area ({((Object)__instance).GetInstanceID()})");
					}
				}
				HandleTimerDictionaries(_orbCartTimers, __instance);
			}
			else if (_orbCartTimers.Remove(__instance) && EnemyValuableTweaks.configEnableDebugLogs.Value)
			{
				EnemyValuableTweaks.Logger.LogDebug((object)$"Removed from safe area ({((Object)__instance).GetInstanceID()})");
			}
		}

		private static void HandleTimerDictionaries(Dictionary<object, float> d, EnemyValuable i)
		{
			if (EnemyValuableTweaks.configEnableDebugLogs.Value)
			{
				EnemyValuableTweaks.Logger.LogDebug((object)$"Dictionary time remaining: {d[i]} {((Object)i).GetInstanceID()}");
			}
			d[i] -= Time.deltaTime;
			if (d[i] <= 0f)
			{
				MakeDestructible(i);
				d.Remove(i);
			}
		}

		private static void MakeDestructible(EnemyValuable i)
		{
			i.indestructibleTimer = 0f;
			i.impactDetector.destroyDisable = false;
			_orbAdditionalCheckDelay.Remove(i);
			EnemyValuableTweaks.Logger.LogInfo((object)$"Made destructible ({((Object)i).GetInstanceID()})");
		}
	}
	[BepInPlugin("BLOKBUSTR.EnemyValuableTweaks", "EnemyValuableTweaks", "1.0.1")]
	public class EnemyValuableTweaks : BaseUnityPlugin
	{
		public static ConfigEntry<string> configReadme;

		public static ConfigEntry<bool> configEnableTimer;

		public static ConfigEntry<float> configTimerLength;

		public static ConfigEntry<float> configAdditionalChecksDelay;

		public static ConfigEntry<bool> configEnableVelocityCheck;

		public static ConfigEntry<float> configVelocityThreshold;

		public static ConfigEntry<bool> configEnablePlayerHold;

		public static ConfigEntry<float> configPlayerHoldTime;

		public static ConfigEntry<bool> configEnableSafeAreaCheck;

		public static ConfigEntry<float> configSafeAreaTime;

		public static ConfigEntry<bool> configEnableDebugLogs;

		internal static EnemyValuableTweaks Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			configReadme = ((BaseUnityPlugin)this).Config.Bind<string>("0 - README", "README", "Note that each category takes priority over the previous. Configs update immediately, especially while in-game if using RepoConfig.", new ConfigDescription("Note that each category takes priority over the previous. Configs update immediately, especially while in-game if using RepoConfig.", (AcceptableValueBase)null, Array.Empty<object>()));
			configEnableTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Timer", "EnableTimer", true, new ConfigDescription("Whether to enable the main timer that automatically disables indestructibility once expired.", (AcceptableValueBase)null, Array.Empty<object>()));
			configTimerLength = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Timer", "TimerLength", 10f, new ConfigDescription("Time in seconds until the orb loses indestructibility. Vanilla default is 5 seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			configAdditionalChecksDelay = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Additional Checks", "AdditionalChecksDelay", 5f, new ConfigDescription("Time in seconds before all following checks activate after the orb has initially spawned. This option reads from the main timer, and will not work if greater than TimerLength. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			configEnableVelocityCheck = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Velocity", "EnableVelocityCheck", true, new ConfigDescription("Automatically disables indestructibility when the orb slows down to a certain velocity threshold. Takes precedence over the timer, meaning it will cut off the timer early if the orb has already reached a standstill.", (AcceptableValueBase)null, Array.Empty<object>()));
			configVelocityThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Velocity", "VelocityThreshold", 0.01f, new ConfigDescription("The minimum threshold for the velocity check.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			configEnablePlayerHold = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Player Hold", "EnablePlayerHold", true, new ConfigDescription("Automatically disables indestructibility when the orb is grabbed by a player.", (AcceptableValueBase)null, Array.Empty<object>()));
			configPlayerHoldTime = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Player Hold", "PlayerHoldTime", 1f, new ConfigDescription("Time in seconds that a player must continue holding onto the orb before indestructibility is disabled. Resets when the player lets go, so that it will not prematurely become destructible if the player gets distracted by something else. Can be set to 0 to immediately disable indestructibility.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			configEnableSafeAreaCheck = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Safe Areas", "EnableSafeAreaCheck", true, new ConfigDescription("Disables indestructibility if the orb has been placed inside a safe area, such as the C.A.R.T. or an extraction point.", (AcceptableValueBase)null, Array.Empty<object>()));
			configSafeAreaTime = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Safe Areas", "SafeAreaTime", 1f, new ConfigDescription("Time in seconds that the orb must remain in a safe area to disable indestructibility. Works very much like PlayerHoldTime.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			configEnableDebugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDebugLogs", false, new ConfigDescription("Enable all debug logs for this mod. Note that this will create quite a bit of spam in the console, so please keep this disabled for normal gameplay!", (AcceptableValueBase)null, Array.Empty<object>()));
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			Logger.LogDebug((object)"Current configs:");
			Logger.LogDebug((object)$"- EnableTimer           = {configEnableTimer.Value}");
			Logger.LogDebug((object)$"- TimerLength           = {configTimerLength.Value}");
			Logger.LogDebug((object)$"- AdditionalChecksDelay = {configAdditionalChecksDelay.Value}");
			Logger.LogDebug((object)$"- EnableVelocityCheck   = {configEnableVelocityCheck.Value}");
			Logger.LogDebug((object)$"- VelocityThreshold     = {configVelocityThreshold.Value}");
			Logger.LogDebug((object)$"- EnablePlayerHold      = {configEnablePlayerHold.Value}");
			Logger.LogDebug((object)$"- PlayerHoldTime        = {configPlayerHoldTime.Value}");
			Logger.LogDebug((object)$"- EnableSafeAreaCheck   = {configEnableSafeAreaCheck.Value}");
			Logger.LogDebug((object)$"- SafeAreaTime          = {configSafeAreaTime.Value}");
			if (configEnableTimer.Value && configAdditionalChecksDelay.Value > configTimerLength.Value)
			{
				Logger.LogWarning((object)$"AdditionalChecksDelay ({configAdditionalChecksDelay.Value}) is greater than TimerLength ({configTimerLength.Value})! Please adjust your config.");
			}
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}