Decompiled source of CheaperEliteBosses v1.0.0

CheaperEliteBosses.dll

Decompiled 2 weeks 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 IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
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: AssemblyCompany("CheaperEliteBosses")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2202d1e0b9f005c3a434479ee6907b05dcde1944")]
[assembly: AssemblyProduct("CheaperEliteBosses")]
[assembly: AssemblyTitle("CheaperEliteBosses")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}
namespace CheaperEliteBosses
{
	[BepInPlugin("com.Moffein.CheaperEliteBosses", "CheaperEliteBosses", "1.0.0")]
	public class CheaperEliteBossesPlugin : BaseUnityPlugin
	{
		public static Dictionary<SpawnCard, CharacterBody> cardToBody = new Dictionary<SpawnCard, CharacterBody>();

		public static ConfigEntry<float> reductionCoefficient;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			reductionCoefficient = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Settings", "Reduction Coefficient"), 1f, new ConfigDescription("0 = Vanilla, 1 = Health Multiplier and Cost Multiplier are the same.", (AcceptableValueBase)null, Array.Empty<object>()));
			CombatDirector.PrepareNewMonsterWave += new Manipulator(CombatDirector_PrepareNewMonsterWave);
			CombatDirector.AttemptSpawnOnTarget += new Manipulator(CombatDirector_AttemptSpawnOnTarget);
		}

		private void CombatDirector_AttemptSpawnOnTarget(ILContext il)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<EliteTierDef>(x, "costMultiplier")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<float, CombatDirector, float>>((Func<float, CombatDirector, float>)((float cost, CombatDirector self) => ReduceCost(cost, self, self.currentActiveEliteTier)));
				if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<EliteTierDef>(x, "costMultiplier")
				}))
				{
					val.Emit(OpCodes.Ldarg_0);
					val.EmitDelegate<Func<float, CombatDirector, float>>((Func<float, CombatDirector, float>)((float cost, CombatDirector self) => ReduceCost(cost, self, self.currentActiveEliteTier)));
					flag = true;
				}
			}
			if (!flag)
			{
				Debug.LogError((object)"CheaperEliteBosses: CombatDirector_AttemptSpawnOnTarget IL hook failed.");
			}
		}

		private void CombatDirector_PrepareNewMonsterWave(ILContext il)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			int eliteTierLoc = -1;
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext(new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref eliteTierLoc),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<EliteTierDef>(x, "costMultiplier")
			}))
			{
				val = new ILCursor(il);
				if (eliteTierLoc >= 0 && val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<CombatDirector>(x, "eliteBias"),
					(Instruction x) => ILPatternMatchingExt.MatchMul(x)
				}))
				{
					val.Emit(OpCodes.Ldarg_0);
					val.Emit(OpCodes.Ldloc, eliteTierLoc);
					val.EmitDelegate<Func<float, CombatDirector, EliteTierDef, float>>((Func<float, CombatDirector, EliteTierDef, float>)((float cost, CombatDirector self, EliteTierDef elite) => ReduceCost(cost, self, elite)));
					flag = true;
				}
			}
			if (!flag)
			{
				Debug.LogError((object)"CheaperEliteBosses: CombatDirector_PrepareNewMonsterWave IL hook failed.");
			}
		}

		public static float ReduceCost(float cost, CombatDirector self, EliteTierDef elite)
		{
			if (self.currentMonsterCard != null && elite != null)
			{
				CharacterBody value = null;
				SpawnCard spawnCard = self.currentMonsterCard.GetSpawnCard();
				if ((Object)(object)spawnCard != (Object)null && !cardToBody.TryGetValue(spawnCard, out value) && Object.op_Implicit((Object)(object)spawnCard.prefab))
				{
					CharacterMaster component = spawnCard.prefab.GetComponent<CharacterMaster>();
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.bodyPrefab))
					{
						value = component.bodyPrefab.GetComponent<CharacterBody>();
						cardToBody.Add(spawnCard, value);
					}
					else
					{
						cardToBody.Add(spawnCard, null);
					}
				}
				if (Object.op_Implicit((Object)(object)value) && value.isChampion && elite.eliteTypes.Length != 0)
				{
					float num = -1f;
					if (elite.availableDefs.Count > 0)
					{
						float num2 = 0f;
						int num3 = 0;
						foreach (EliteDef availableDef in elite.availableDefs)
						{
							if (!((Object)(object)availableDef == (Object)null))
							{
								num2 += availableDef.healthBoostCoefficient;
								num3++;
							}
						}
						if (num3 > 0)
						{
							num = num2 / (float)num3;
						}
					}
					if (num > 0f)
					{
						float num4 = elite.costMultiplier - num;
						float num5 = Mathf.Max(elite.costMultiplier - num4 * reductionCoefficient.Value, 0.01f);
						return cost * num5 / elite.costMultiplier;
					}
				}
			}
			return cost;
		}
	}
}