Decompiled source of DynamicBarrierDecay v2.0.2

DynamicBarrierDecay.dll

Decompiled 2 months ago
using System;
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.RoR2;
using R2API.Utils;
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("DynamicBarrierDecay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cdbdfa5ce0bddd8135a7eac9a9792b889f8b2538")]
[assembly: AssemblyProduct("DynamicBarrierDecay")]
[assembly: AssemblyTitle("DynamicBarrierDecay")]
[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 DynamicBarrierDecay
{
	[BepInPlugin("com.zombieseatflesh7.dynamicbarrierdecay", "DynamicBarrierDecay", "2.0.1")]
	public class DynamicBarrierDecay : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_AddBarrier <0>__HealthComponent_AddBarrier;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_FixedUpdate <>9__4_0;

			internal void <Awake>b__4_0(orig_FixedUpdate orig, CharacterBody self)
			{
				orig.Invoke(self);
				Reflection.SetPropertyValue<float>((object)self, "barrierDecayRate", Math.Max(MinDecayRate.Value, self.healthComponent.barrier * decayRate));
			}
		}

		public static ConfigEntry<float> HalfLife;

		public static ConfigEntry<float> MinDecayRate;

		public static ConfigEntry<bool> UnlimitedBarrier;

		public static float decayRate = 0.0924196f;

		public void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			InitConfigs();
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				hook_FixedUpdate val = delegate(orig_FixedUpdate orig, CharacterBody self)
				{
					orig.Invoke(self);
					Reflection.SetPropertyValue<float>((object)self, "barrierDecayRate", Math.Max(MinDecayRate.Value, self.healthComponent.barrier * decayRate));
				};
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			CharacterBody.FixedUpdate += (hook_FixedUpdate)obj;
			if (UnlimitedBarrier.Value)
			{
				object obj2 = <>O.<0>__HealthComponent_AddBarrier;
				if (obj2 == null)
				{
					hook_AddBarrier val2 = HealthComponent_AddBarrier;
					<>O.<0>__HealthComponent_AddBarrier = val2;
					obj2 = (object)val2;
				}
				HealthComponent.AddBarrier += (hook_AddBarrier)obj2;
			}
		}

		private void InitConfigs()
		{
			MinDecayRate = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Minimum Decay Rate", 3f, "The minimum decay rate for barrier measured in points per second. Can be a number between 0 and infinity.");
			HalfLife = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Barrier Half-Life", 7.5f, "The amound of time in seconds it takes for barrier to decay to half of its original amount. Lower numbers means faster barrier decay. Can be a number between 0 and infinity. Setting to 0 makes barrier disappear instantly.");
			UnlimitedBarrier = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Unlimited Barrier", false, "Setting this to true will remove the barrier limit, allowing the player to get unlimited barrier.");
			if (HalfLife.Value <= 0f)
			{
				decayRate = float.MaxValue;
			}
			else
			{
				decayRate = (float)(Math.Log(2.0) / (double)HalfLife.Value);
			}
		}

		private static void HealthComponent_AddBarrier(orig_AddBarrier orig, HealthComponent self, float value)
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void RoR2.HealthComponent::AddBarrier(System.Single)' called on client");
			}
			else if (self.alive)
			{
				self.Networkbarrier = self.barrier + value;
			}
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

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

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

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

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

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

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

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