Decompiled source of HordeTweaks v1.0.0

HordeTweaks.dll

Decompiled a month 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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
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("HordeTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6a80699f05d866e7c321b8d45d74e342cd56878")]
[assembly: AssemblyProduct("HordeTweaks")]
[assembly: AssemblyTitle("HordeTweaks")]
[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 HordeTweaks
{
	[BepInPlugin("acats.HordeTweaks", "HordeTweaks", "1.0.0")]
	public class HordeTweaks : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_SetNextSpawnAsBoss <>9__5_0;

			public static hook_AttemptSpawnOnTarget <>9__6_0;

			public static hook_OnMemberDefeatedServer <>9__7_0;

			internal void <RandomHordeChance>b__5_0(orig_SetNextSpawnAsBoss orig, CombatDirector self)
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self);
				if (Run.instance.stageRng.RangeFloat(0f, 100f) > HordeTweaksConfig.RandomHordeChance.Value)
				{
					return;
				}
				WeightedSelection<DirectorCard> val = new WeightedSelection<DirectorCard>(8);
				for (int i = 0; i < self.finalMonsterCardsSelection.Count; i++)
				{
					ChoiceInfo<DirectorCard> choice = self.finalMonsterCardsSelection.GetChoice(i);
					DirectorCard value = choice.value;
					SpawnCard spawnCard = value.spawnCard;
					if (value.IsAvailable() && !spawnCard.prefab.GetComponent<CharacterMaster>().bodyPrefab.GetComponent<CharacterBody>().isChampion && !((float)value.cost * CombatDirector.CalcHighestEliteCostMultiplier(value.spawnCard.eliteRules) * (float)HordeTweaksConfig.MaxHordeEnemies.Value < self.monsterCredit))
					{
						val.AddChoice(choice);
					}
				}
				if (val.Count != 0)
				{
					DirectorCard val2 = val.Evaluate(Run.instance.stageRng.nextNormalizedFloat);
					self.OverrideCurrentMonsterCard(val2);
				}
			}

			internal bool <MaxHordeEnemies>b__6_0(orig_AttemptSpawnOnTarget orig, CombatDirector self, Transform transform, PlacementMode placementMode)
			{
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (self.currentMonsterCard == null || (Object)(object)self != (Object)(object)TeleporterInteraction.instance?.bossDirector)
				{
					return orig.Invoke(self, transform, placementMode);
				}
				if (self.currentMonsterCard.spawnCard.prefab.GetComponent<CharacterMaster>().bodyPrefab.GetComponent<CharacterBody>().isChampion)
				{
					return orig.Invoke(self, transform, placementMode);
				}
				int maximumNumberToSpawnBeforeSkipping = self.maximumNumberToSpawnBeforeSkipping;
				self.maximumNumberToSpawnBeforeSkipping = HordeTweaksConfig.MaxHordeEnemies.Value;
				bool result = orig.Invoke(self, transform, placementMode);
				self.maximumNumberToSpawnBeforeSkipping = maximumNumberToSpawnBeforeSkipping;
				return result;
			}

			internal void <RedDropChance>b__7_0(orig_OnMemberDefeatedServer orig, BossGroup self, CharacterMaster memberMaster, DamageReport damageReport)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				orig.Invoke(self, memberMaster, damageReport);
				if (!memberMaster.bodyPrefab.GetComponent<CharacterBody>().isChampion && self.bossDrops.Count == 0)
				{
					List<PickupIndex> availableTier3DropList = Run.instance.availableTier3DropList;
					self.bossDrops.Add(availableTier3DropList[self.rng.RangeInt(0, availableTier3DropList.Count)]);
					self.bossDropChance = HordeTweaksConfig.RedDropChance.Value / 100f;
				}
			}
		}

		public const string PluginGUID = "acats.HordeTweaks";

		public const string PluginAuthor = "acats";

		public const string PluginName = "HordeTweaks";

		public const string PluginVersion = "1.0.0";

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			HordeTweaksConfig.Init(((BaseUnityPlugin)this).Config);
			if (HordeTweaksConfig.RandomHordeChance.Value > 0f)
			{
				RandomHordeChance();
			}
			if (HordeTweaksConfig.MaxHordeEnemies.Value > 0)
			{
				MaxHordeEnemies();
			}
			if (HordeTweaksConfig.RedDropChance.Value > 0f)
			{
				RedDropChance();
			}
		}

		private static void RandomHordeChance()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__5_0;
			if (obj == null)
			{
				hook_SetNextSpawnAsBoss val = delegate(orig_SetNextSpawnAsBoss orig, CombatDirector self)
				{
					//IL_003f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0044: Unknown result type (might be due to invalid IL or missing references)
					//IL_0045: Unknown result type (might be due to invalid IL or missing references)
					//IL_008b: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
					orig.Invoke(self);
					if (!(Run.instance.stageRng.RangeFloat(0f, 100f) > HordeTweaksConfig.RandomHordeChance.Value))
					{
						WeightedSelection<DirectorCard> val2 = new WeightedSelection<DirectorCard>(8);
						for (int i = 0; i < self.finalMonsterCardsSelection.Count; i++)
						{
							ChoiceInfo<DirectorCard> choice = self.finalMonsterCardsSelection.GetChoice(i);
							DirectorCard value = choice.value;
							SpawnCard spawnCard = value.spawnCard;
							if (value.IsAvailable() && !spawnCard.prefab.GetComponent<CharacterMaster>().bodyPrefab.GetComponent<CharacterBody>().isChampion && !((float)value.cost * CombatDirector.CalcHighestEliteCostMultiplier(value.spawnCard.eliteRules) * (float)HordeTweaksConfig.MaxHordeEnemies.Value < self.monsterCredit))
							{
								val2.AddChoice(choice);
							}
						}
						if (val2.Count != 0)
						{
							DirectorCard val3 = val2.Evaluate(Run.instance.stageRng.nextNormalizedFloat);
							self.OverrideCurrentMonsterCard(val3);
						}
					}
				};
				<>c.<>9__5_0 = val;
				obj = (object)val;
			}
			CombatDirector.SetNextSpawnAsBoss += (hook_SetNextSpawnAsBoss)obj;
		}

		private static void MaxHordeEnemies()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__6_0;
			if (obj == null)
			{
				hook_AttemptSpawnOnTarget val = delegate(orig_AttemptSpawnOnTarget orig, CombatDirector self, Transform transform, PlacementMode placementMode)
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_0077: Unknown result type (might be due to invalid IL or missing references)
					//IL_0055: Unknown result type (might be due to invalid IL or missing references)
					if (self.currentMonsterCard == null || (Object)(object)self != (Object)(object)TeleporterInteraction.instance?.bossDirector)
					{
						return orig.Invoke(self, transform, placementMode);
					}
					if (!self.currentMonsterCard.spawnCard.prefab.GetComponent<CharacterMaster>().bodyPrefab.GetComponent<CharacterBody>().isChampion)
					{
						int maximumNumberToSpawnBeforeSkipping = self.maximumNumberToSpawnBeforeSkipping;
						self.maximumNumberToSpawnBeforeSkipping = HordeTweaksConfig.MaxHordeEnemies.Value;
						bool result = orig.Invoke(self, transform, placementMode);
						self.maximumNumberToSpawnBeforeSkipping = maximumNumberToSpawnBeforeSkipping;
						return result;
					}
					return orig.Invoke(self, transform, placementMode);
				};
				<>c.<>9__6_0 = val;
				obj = (object)val;
			}
			CombatDirector.AttemptSpawnOnTarget += (hook_AttemptSpawnOnTarget)obj;
		}

		private static void RedDropChance()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			object obj = <>c.<>9__7_0;
			if (obj == null)
			{
				hook_OnMemberDefeatedServer val = delegate(orig_OnMemberDefeatedServer orig, BossGroup self, CharacterMaster memberMaster, DamageReport damageReport)
				{
					//IL_004d: Unknown result type (might be due to invalid IL or missing references)
					orig.Invoke(self, memberMaster, damageReport);
					if (!memberMaster.bodyPrefab.GetComponent<CharacterBody>().isChampion && self.bossDrops.Count == 0)
					{
						List<PickupIndex> availableTier3DropList = Run.instance.availableTier3DropList;
						self.bossDrops.Add(availableTier3DropList[self.rng.RangeInt(0, availableTier3DropList.Count)]);
						self.bossDropChance = HordeTweaksConfig.RedDropChance.Value / 100f;
					}
				};
				<>c.<>9__7_0 = val;
				obj = (object)val;
			}
			BossGroup.OnMemberDefeatedServer += (hook_OnMemberDefeatedServer)obj;
		}
	}
	internal static class HordeTweaksConfig
	{
		public static ConfigEntry<float> RandomHordeChance;

		public static ConfigEntry<int> MaxHordeEnemies;

		public static ConfigEntry<float> RedDropChance;

		internal static void Init(ConfigFile config)
		{
			RandomHordeChance = config.Bind<float>("General", "Random Horde Chance (%)", 5f, "The chance for a horde of many to be deliberately picked (in vanilla they're only picked if the game fails to spawn a normal boss)");
			MaxHordeEnemies = config.Bind<int>("General", "Maximum Horde Size", 36, "The maximum number of enemies that can be spawned in a horde of many. Vanilla is 6");
			RedDropChance = config.Bind<float>("General", "Legendary Item Drop Chance (%)", 10f, "Chance to replace green items from the teleporter with red items. Vanilla yellow items have a 15% chance");
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

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