Decompiled source of CoinPiercerWallbang v1.0.0

CoinPiercerWallbang.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PiercerWallbang")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PiercerWallbang")]
[assembly: AssemblyTitle("PiercerWallbang")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 PiercerWallbang
{
	[BepInPlugin("DestinedSnow.CoinPiercerwallbangConfig", "CoinPiercer Wallbang", "1.0.0")]
	[BepInProcess("ULTRAKILL.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static BoolValueChangeEventDelegate <>9__10_0;

			public static BoolValueChangeEventDelegate <>9__10_1;

			internal void <Awake>b__10_0(BoolValueChangeEvent data)
			{
				CoinWallbang.Value = data.value;
			}

			internal void <Awake>b__10_1(BoolValueChangeEvent data)
			{
				DirectWallbang.Value = data.value;
			}
		}

		public const string ModGuid = "DestinedSnow.CoinPiercerwallbangConfig";

		public const string ModName = "CoinPiercer Wallbang";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		public static PluginConfigurator PluginConfigInstance;

		public static BoolField CoinWallbangField;

		public static BoolField DirectWallbangField;

		internal static ConfigEntry<bool> CoinWallbang;

		internal static ConfigEntry<bool> DirectWallbang;

		private Harmony harmony;

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			CoinWallbang = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CoinWallbang", true, (ConfigDescription)null);
			DirectWallbang = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DirectWallbang", true, (ConfigDescription)null);
			harmony = new Harmony("DestinedSnow.CoinPiercerwallbangConfig");
			harmony.PatchAll();
			PluginConfigInstance = PluginConfigurator.Create("Coin Piercer Wallbang", "Coin Piercer Wallbang Config");
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string iconWithURL = "file:///" + Path.Combine(directoryName, "icon.png").Replace("\\", "/");
			PluginConfigInstance.SetIconWithURL(iconWithURL);
			CoinWallbangField = new BoolField(PluginConfigInstance.rootPanel, "Coin Wallbang", "coin_wallbang", CoinWallbang.Value);
			BoolField coinWallbangField = CoinWallbangField;
			object obj = <>c.<>9__10_0;
			if (obj == null)
			{
				BoolValueChangeEventDelegate val = delegate(BoolValueChangeEvent data)
				{
					CoinWallbang.Value = data.value;
				};
				<>c.<>9__10_0 = val;
				obj = (object)val;
			}
			coinWallbangField.onValueChange += (BoolValueChangeEventDelegate)obj;
			DirectWallbangField = new BoolField(PluginConfigInstance.rootPanel, "Direct Piercer Wallbang", "direct_wallbang", DirectWallbang.Value);
			BoolField directWallbangField = DirectWallbangField;
			object obj2 = <>c.<>9__10_1;
			if (obj2 == null)
			{
				BoolValueChangeEventDelegate val2 = delegate(BoolValueChangeEvent data)
				{
					DirectWallbang.Value = data.value;
				};
				<>c.<>9__10_1 = val2;
				obj2 = (object)val2;
			}
			directWallbangField.onValueChange += (BoolValueChangeEventDelegate)obj2;
			Log.LogInfo((object)"CoinPiercer Wallbang 1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		internal static bool IsChargedPiercer(RevolverBeam beam)
		{
			if ((Object)(object)beam == (Object)null)
			{
				return false;
			}
			if (beam.gunVariation != 0)
			{
				return false;
			}
			int num = (beam.strongAlt ? 6 : 3);
			return beam.hitAmount >= num;
		}
	}
	[HarmonyPatch(typeof(Coin), "CheckEnemyObstruction")]
	internal static class CoinCheckEnemyObstructionPatch
	{
		private static bool Prefix(Coin __instance, ref bool __result)
		{
			if (!Plugin.CoinWallbang.Value)
			{
				return true;
			}
			try
			{
				GameObject value = Traverse.Create((object)__instance).Field("altBeam").GetValue<GameObject>();
				if ((Object)(object)value == (Object)null)
				{
					return true;
				}
				RevolverBeam component = value.GetComponent<RevolverBeam>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				if (!Plugin.IsChargedPiercer(component))
				{
					return true;
				}
				__result = true;
				return false;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"CoinCheckEnemyObstructionPatch error: {arg}");
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(RevolverBeam), "Shoot")]
	internal static class BeamDistancePatch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private FieldInfo <distanceField>5__1;

			private MethodInfo <modifyMethod>5__2;

			private IEnumerator<CodeInstruction> <>s__3;

			private CodeInstruction <code>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<distanceField>5__1 = null;
				<modifyMethod>5__2 = null;
				<>s__3 = null;
				<code>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Expected O, but got Unknown
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<distanceField>5__1 = AccessTools.Field(typeof(PhysicsCastResult), "distance");
						<modifyMethod>5__2 = AccessTools.Method(typeof(BeamDistancePatch), "ModifyDistance", (Type[])null, (Type[])null);
						<>s__3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						if (<code>5__4.opcode == OpCodes.Ldfld && object.Equals(<code>5__4.operand, <distanceField>5__1))
						{
							<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							<>1__state = 2;
							return true;
						}
						goto IL_014b;
					case 2:
						<>1__state = -3;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)<modifyMethod>5__2);
						<>1__state = 3;
						return true;
					case 3:
						{
							<>1__state = -3;
							goto IL_014b;
						}
						IL_014b:
						<code>5__4 = null;
						break;
					}
					if (<>s__3.MoveNext())
					{
						<code>5__4 = <>s__3.Current;
						<>2__current = <code>5__4;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>s__3 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__3 != null)
				{
					<>s__3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__1 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__1(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		private static float ModifyDistance(float distance, RevolverBeam beam)
		{
			if (!Plugin.DirectWallbang.Value)
			{
				return distance;
			}
			if (Plugin.IsChargedPiercer(beam))
			{
				return 1000f;
			}
			return distance;
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__1(-2)
			{
				<>3__instructions = instructions
			};
		}
	}
}