Decompiled source of EnemyVariety v0.2.0

EnemyVariety.dll

Decompiled 10 hours 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 System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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 Local.Enemy.Variety
{
	[BepInPlugin("local.enemy.variety", "EnemyVariety", "0.2.0")]
	internal class Plugin : BaseUnityPlugin
	{
		public const string version = "0.2.0";

		public const string identifier = "local.enemy.variety";

		private static ConfigEntry<bool> boss;

		protected async void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			boss = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Apply to Teleporter Boss", true, "If enabled, multiple boss types may appear during the teleporter event.");
			CombatDirector[] componentsInChildren = (await Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/ShrineHalcyonite.prefab").Task).GetComponentsInChildren<CombatDirector>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].resetMonsterCardIfFailed = false;
			}
		}

		[HarmonyPatch(typeof(CombatDirector), "AttemptSpawnOnTarget")]
		[HarmonyPrefix]
		private static void ResetMonsterCard(CombatDirector __instance, ref bool __state)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			ref DirectorCard currentMonsterCard = ref __instance.currentMonsterCard;
			WeightedSelection<DirectorCard> finalMonsterCardsSelection = __instance.finalMonsterCardsSelection;
			__state = false;
			if (!__instance.resetMonsterCardIfFailed || currentMonsterCard == null || finalMonsterCardsSelection == null)
			{
				return;
			}
			ChoiceInfo<DirectorCard>[] choices = finalMonsterCardsSelection.choices;
			for (int i = 0; i < choices.Length; i++)
			{
				ChoiceInfo<DirectorCard> val = choices[i];
				if (!object.Equals(currentMonsterCard, val.value) || val.weight <= 0f || currentMonsterCard.cost <= 0)
				{
					continue;
				}
				int spawnCountInCurrentWave = __instance.spawnCountInCurrentWave;
				int cost = currentMonsterCard.cost;
				do
				{
					if ((Object)(object)__instance == (Object)(object)TeleporterInteraction.instance?.bossDirector)
					{
						if (!boss.Value)
						{
							break;
						}
						__instance.SetNextSpawnAsBoss();
						__state = spawnCountInCurrentWave == 0 || (float)currentMonsterCard.cost <= __instance.monsterCredit;
					}
					else
					{
						Xoroshiro128Plus rng = __instance.rng;
						do
						{
							currentMonsterCard = finalMonsterCardsSelection.Evaluate(rng.nextNormalizedFloat);
						}
						while ((float)currentMonsterCard.cost < rng.nextNormalizedFloat * __instance.monsterCredit);
						__instance.PrepareNewMonsterWave(currentMonsterCard);
					}
				}
				while (currentMonsterCard.cost > cost && (float)currentMonsterCard.cost > __instance.monsterCredit);
				__instance.spawnCountInCurrentWave = spawnCountInCurrentWave;
				break;
			}
		}

		[HarmonyPatch(typeof(CombatDirector), "AttemptSpawnOnTarget")]
		[HarmonyPostfix]
		private static void RetryIfNodePlacementFailed(bool __state, ref bool __result)
		{
			__result |= __state;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Chat), "SendBroadcastChat", new Type[] { typeof(ChatMessageBase) })]
		private static void ChangeMessage(ChatMessageBase message)
		{
			SubjectFormatChatMessage val = (SubjectFormatChatMessage)(object)((message is SubjectFormatChatMessage) ? message : null);
			if (val != null)
			{
				bool? flag = val.paramTokens?.Any();
				if (flag.HasValue && flag.GetValueOrDefault() && ((SubjectChatMessage)val).baseToken == "SHRINE_COMBAT_USE_MESSAGE")
				{
					val.paramTokens[0] = Language.GetString("LOGBOOK_CATEGORY_MONSTER").ToLower();
				}
			}
		}

		[HarmonyPatch(typeof(BossGroup), "UpdateBossMemories")]
		[HarmonyPostfix]
		private static void UpdateTitle(BossGroup __instance)
		{
			if (!boss.Value)
			{
				return;
			}
			Dictionary<(string, string), float> dictionary = new Dictionary<(string, string), float>();
			float num = 0f;
			for (int i = 0; i < __instance.bossMemoryCount; i++)
			{
				CharacterBody cachedBody = __instance.bossMemories[i].cachedBody;
				if (!Object.op_Implicit((Object)(object)cachedBody))
				{
					continue;
				}
				HealthComponent healthComponent = cachedBody.healthComponent;
				if (!(((healthComponent != null) ? new bool?(healthComponent.alive) : null) ?? true))
				{
					continue;
				}
				string bestBodyName = Util.GetBestBodyName(((Component)cachedBody).gameObject);
				string text = cachedBody.GetSubtitle();
				(string, string) key = (bestBodyName, text);
				if (!dictionary.ContainsKey(key))
				{
					dictionary[key] = 0f;
				}
				dictionary[key] += healthComponent.combinedHealth + healthComponent.missingCombinedHealth * 4f;
				if (dictionary[key] > num)
				{
					num = dictionary[key];
					if (string.IsNullOrEmpty(text))
					{
						text = Language.GetString("NULL_SUBTITLE");
					}
					__instance.bestObservedName = bestBodyName;
					__instance.bestObservedSubtitle = "<sprite name=\"CloudLeft\" tint=1> " + text + " <sprite name=\"CloudRight\" tint=1>";
				}
			}
		}

		[HarmonyPatch(typeof(CombatDirector), "SpendAllCreditsOnMapSpawns")]
		[HarmonyPrefix]
		private static void PopulateScene(CombatDirector __instance, ref bool __state)
		{
			__state = __instance.resetMonsterCardIfFailed;
			if (SceneCatalog.mostRecentSceneDef.stageOrder > Run.stagesPerLoop)
			{
				__instance.resetMonsterCardIfFailed = false;
			}
		}

		[HarmonyPatch(typeof(CombatDirector), "SpendAllCreditsOnMapSpawns")]
		[HarmonyPostfix]
		private static void RestoreValue(CombatDirector __instance, bool __state)
		{
			__instance.resetMonsterCardIfFailed = __state;
		}
	}
}