Decompiled source of VoidFogNerf v1.2.3

VoidFogNerf.dll

Decompiled a week 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 IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;

[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("VoidFogNerf")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e8a6dd039e7b39706d87ba22b28dc95772e7a3bd")]
[assembly: AssemblyProduct("VoidFogNerf")]
[assembly: AssemblyTitle("VoidFogNerf")]
[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 VoidFogNerf
{
	internal static class VFNConfig
	{
		public static ConfigEntry<float> fogDamageAmp;

		public static ConfigEntry<bool> useCurrentHealth;

		private static ConfigEntry<bool> bypassArmor;

		private static ConfigEntry<bool> bypassBlock;

		private static ConfigEntry<bool> nonlethal;

		public static int damageType;

		public static void InitializeConfig()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Paths.ConfigPath + "\\OakPrime.VoidFogNerf.cfg", true);
			useCurrentHealth = val.Bind<bool>("Main", "Use current health", true, "Change fog damage to percent of current health instead of max health");
			fogDamageAmp = val.Bind<float>("Main", "Void Fog damage multiplier", 1.3f, "Multiplier for void fog damage. Default: 1.3 (x current health). Vanilla: 1.0 (x max health).");
			bypassArmor = val.Bind<bool>("Main", "Bypass armor", false, "Void fog bypasses armor and repulsion armor. Default: false. Vanilla: true.");
			bypassBlock = val.Bind<bool>("Main", "Bypass block", false, "Void fog bypasses block from bears. Default: false. Vanilla: true.");
			nonlethal = val.Bind<bool>("Main", "Nonlethal", false, "Void fog damage cannot take you below 1 hp.");
			damageType = 2;
			damageType = (bypassArmor.Value ? 2 : 0) + (bypassBlock.Value ? 64 : 0) + (nonlethal.Value ? 1 : 0);
		}
	}
	[BepInPlugin("OakPrime.VoidFogNerf", "VoidFogNerf", "1.2.3")]
	public class VoidFogNerf : BaseUnityPlugin
	{
		public const string PluginGUID = "OakPrime.VoidFogNerf";

		public const string PluginAuthor = "OakPrime";

		public const string PluginName = "VoidFogNerf";

		public const string PluginVersion = "1.2.3";

		public void Awake()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			try
			{
				VFNConfig.InitializeConfig();
				FogDamageController.MyFixedUpdate += (Manipulator)delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
					//IL_0106: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val = new ILCursor(il);
					if (VFNConfig.useCurrentHealth.Value)
					{
						if (!val.TryGotoNext(new Func<Instruction, bool>[2]
						{
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "get_healthComponent"),
							(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<HealthComponent>(x, "get_fullCombinedHealth")
						}))
						{
							((BaseUnityPlugin)this).Logger.LogError((object)("TryGoToNext failed to find fullCombinedHealth instructions in method: " + (object)val.Method));
							return;
						}
						int index = val.Index;
						val.Index = index + 1;
						val.RemoveRange(1);
						val.EmitDelegate<Func<HealthComponent, float>>((Func<HealthComponent, float>)((HealthComponent healthComponent) => healthComponent.combinedHealth));
						index = val.Index;
						val.Index = index + 1;
						val.Emit(OpCodes.Ldc_R4, VFNConfig.fogDamageAmp.Value);
						val.Emit(OpCodes.Mul);
					}
					MethodReference val2 = default(MethodReference);
					if (!val.TryGotoNext(new Func<Instruction, bool>[2]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 66),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref val2)
					}))
					{
						((BaseUnityPlugin)this).Logger.LogError((object)("TryGoToNext failed to find damageType instructions in method: " + (object)val.Method));
					}
					else
					{
						int index = val.Index;
						val.Index = index + 1;
						val.EmitDelegate<Func<int, int>>((Func<int, int>)((int damageType) => VFNConfig.damageType));
					}
				};
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)(ex.Message + " - " + ex.StackTrace));
			}
		}
	}
}