Decompiled source of SwarmsFix v1.0.0

SwarmsFix.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SwarmsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+737e165dcb4ac73e88d2e5be799f1f3ee241ef1a")]
[assembly: AssemblyProduct("SwarmsFix")]
[assembly: AssemblyTitle("SwarmsFix")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
namespace SwarmsFix
{
	[BepInPlugin("dolso.SwarmsFix", "SwarmsFix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private IDetour hook;

		private void Awake()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			hook = (IDetour)new ILHook((MethodBase)typeof(CombatDirector).GetMethod("Spawn", new Type[8]
			{
				typeof(SpawnCard),
				typeof(EliteDef),
				typeof(Transform),
				typeof(MonsterSpawnDistance),
				typeof(bool),
				typeof(float),
				typeof(PlacementMode),
				typeof(bool)
			}), new Manipulator(FixSwarms));
		}

		private void FixSwarms(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_009f: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			VariableDefinition val2 = ((IEnumerable<VariableDefinition>)il.Body.Variables).First((VariableDefinition a) => ((MemberReference)((VariableReference)a).VariableType).Name == "DirectorPlacementRule");
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction a) => ILPatternMatchingExt.MatchStfld<DirectorPlacementRule>(a, "minDistance")
			}))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Failed to find instruction");
				return;
			}
			val.Emit(OpCodes.Ldloc, val2);
			val.Emit(OpCodes.Dup);
			val.Emit(OpCodes.Dup);
			val.Emit<DirectorPlacementRule>(OpCodes.Ldfld, "maxDistance");
			val.Emit<DirectorPlacementRule>(OpCodes.Stfld, "maxDistanceSwarms");
			val.Emit(OpCodes.Dup);
			val.Emit<DirectorPlacementRule>(OpCodes.Ldfld, "minDistance");
			val.Emit<DirectorPlacementRule>(OpCodes.Stfld, "minDistanceSwarms");
		}
	}
}