Decompiled source of PerfectedLoopTri v1.0.1

plugin/PerfectedLoopTri.dll

Decompiled 2 months ago
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.Logging;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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 = "")]
[assembly: AssemblyCompany("PerfectedLoopTri")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PerfectedLoopTri")]
[assembly: AssemblyTitle("PerfectedLoopTri")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PerfectedLoopTri;

public enum ConfigAddTo
{
	Disable,
	TierGilded,
	TierTwo
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.kking117.PerfectedLoop3", "PerfectedLoop3", "1.0.1")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class PerfectedLoopTri : BaseUnityPlugin
{
	public const string MODUID = "com.kking117.PerfectedLoop3";

	public const string MODNAME = "PerfectedLoop3";

	public const string MODVERSION = "1.0.1";

	internal static ManualLogSource ModLogger;

	internal static PluginInfo pluginInfo;

	private float Tier_Lunar_Cost = 6f;

	private float Lunar_Perfected_Health = 2f;

	private float Lunar_Perfected_Damage = 2f;

	private bool Tier_Gilded_AllowAny = false;

	private float Tier_Gilded_Cost = 3.5f;

	private int Tier_Gilded_StageCount = 3;

	private bool Tier_Gilded_Fix = true;

	private ConfigAddTo Gilded_Tier = ConfigAddTo.TierGilded;

	private float Gilded_Health = 6f;

	private float Gilded_Damage = 3f;

	private ConfigAddTo Mod_Perfected_Tier = ConfigAddTo.TierTwo;

	private float Mod_Perfected_Health = 14.4f;

	private float Mod_Perfected_Damage = 6f;

	private ConfigAddTo Mod_Void_Tier = ConfigAddTo.Disable;

	private float Mod_Void_Health = 1f;

	private float Mod_Void_Damage = 1f;

	private bool Director_Enable = false;

	private EliteDef voidDef = Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC1/EliteVoid/edVoid.asset").WaitForCompletion();

	private EliteDef perfectedDef = Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLunar/edLunar.asset").WaitForCompletion();

	private EliteDef gildedDef = Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC2/Elites/EliteAurelionite/edAurelionite.asset").WaitForCompletion();

	public EliteDef Custom_VoidDef = null;

	public EliteDef Custom_PerfectedDef = null;

	public void Awake()
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		ModLogger = ((BaseUnityPlugin)this).Logger;
		pluginInfo = ((BaseUnityPlugin)this).Info;
		ReadConfigs();
		UpdatePerfected();
		UpdateGilded();
		if (Mod_Perfected_Tier != 0)
		{
			CreatePerfected();
		}
		if (Mod_Void_Tier != 0)
		{
			CreateVoid();
		}
		CombatDirector.Init += new hook_Init(OnInit);
		if (Director_Enable)
		{
			CombatDirector.ResetEliteType += new hook_ResetEliteType(ResetEliteType);
			CombatDirector.PrepareNewMonsterWave += new hook_PrepareNewMonsterWave(OnSelectEliteTier);
		}
	}

	private void ResetEliteType(orig_ResetEliteType orig, CombatDirector self)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		List<EliteTierDef> list = new List<EliteTierDef>();
		EliteTierDef currentActiveEliteTier = null;
		float num = 9999f;
		self.currentActiveEliteTier = CombatDirector.eliteTiers[0];
		for (int i = 0; i < CombatDirector.eliteTiers.Length; i++)
		{
			EliteTierDef val = CombatDirector.eliteTiers[i];
			if (val.CanSelect(self.currentMonsterCard.spawnCard.eliteRules))
			{
				if (val.costMultiplier < num)
				{
					currentActiveEliteTier = val;
					num = val.costMultiplier;
				}
				list.Add(val);
			}
		}
		self.currentActiveEliteTier = currentActiveEliteTier;
		if (list.Count > 0)
		{
			List<EliteTierDef> list2 = new List<EliteTierDef>();
			for (int j = 0; j < list.Count; j++)
			{
				EliteTierDef val2 = list[j];
				if (val2.costMultiplier <= num)
				{
					int num2 = 0;
					if (val2.canSelectWithoutAvailableEliteDef)
					{
						num2++;
					}
					if (val2.availableDefs != null)
					{
						num2 += val2.eliteTypes.Length;
					}
					while (num2 > 0)
					{
						list2.Add(val2);
						num2--;
					}
				}
			}
			if (list2.Count > 0)
			{
				self.currentActiveEliteTier = self.rng.NextElementUniform<EliteTierDef>(list2);
			}
		}
		self.currentActiveEliteDef = self.currentActiveEliteTier.GetRandomAvailableEliteDef(self.rng);
	}

	private void OnSelectEliteTier(orig_PrepareNewMonsterWave orig, CombatDirector self, DirectorCard monsterCard)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		self.currentMonsterCard = monsterCard;
		self.ResetEliteType();
		SpawnCard spawnCard = self.currentMonsterCard.spawnCard;
		if (!((CharacterSpawnCard)((spawnCard is CharacterSpawnCard) ? spawnCard : null)).noElites)
		{
			EliteTierDef val = null;
			List<EliteTierDef> list = new List<EliteTierDef>();
			List<EliteTierDef> list2 = new List<EliteTierDef>();
			for (int i = 1; i < CombatDirector.eliteTiers.Length; i++)
			{
				EliteTierDef val2 = CombatDirector.eliteTiers[i];
				if (!val2.CanSelect(self.currentMonsterCard.spawnCard.eliteRules))
				{
					continue;
				}
				float num = (float)self.currentMonsterCard.cost * val2.costMultiplier * self.eliteBias;
				if (!(num <= self.monsterCredit))
				{
					continue;
				}
				if (val != null)
				{
					if (val.costMultiplier < val2.costMultiplier)
					{
						val = val2;
					}
				}
				else
				{
					val = val2;
				}
				list.Add(val2);
			}
			if (val != null)
			{
				float costMultiplier = val.costMultiplier;
				if (list.Count > 1)
				{
					for (int j = 0; j < list.Count; j++)
					{
						EliteTierDef val3 = list[j];
						if (val3.costMultiplier >= costMultiplier)
						{
							int num2 = 0;
							if (val3.canSelectWithoutAvailableEliteDef)
							{
								num2++;
							}
							if (val3.availableDefs != null)
							{
								num2 += val3.eliteTypes.Length;
							}
							while (num2 > 0)
							{
								list2.Add(val3);
								num2--;
							}
						}
					}
				}
				if (list2.Count > 0)
				{
					self.currentActiveEliteTier = self.rng.NextElementUniform<EliteTierDef>(list2);
				}
				else
				{
					self.currentActiveEliteTier = val;
				}
			}
		}
		self.currentActiveEliteDef = self.currentActiveEliteTier.GetRandomAvailableEliteDef(self.rng);
		self.lastAttemptedMonsterCard = self.currentMonsterCard;
		self.spawnCountInCurrentWave = 0;
	}

	private void OnInit(orig_Init orig)
	{
		orig.Invoke();
		EliteTierDef val = EliteAPI.VanillaEliteTiers[3];
		if (val != null)
		{
			if (Tier_Gilded_Fix)
			{
				List<EliteDef> list = val.eliteTypes.ToList();
				List<EliteDef> list2 = new List<EliteDef>
				{
					Elites.Fire,
					Elites.Lightning,
					Elites.Ice,
					Elites.Earth
				};
				foreach (EliteDef item in list2)
				{
					list.Remove(item);
				}
				if (Mod_Perfected_Tier == ConfigAddTo.TierGilded)
				{
					list.Add(Custom_PerfectedDef);
				}
				if (Mod_Void_Tier == ConfigAddTo.TierGilded)
				{
					list.Add(Custom_VoidDef);
				}
				if (Gilded_Tier == ConfigAddTo.TierGilded)
				{
					list.Add(gildedDef);
				}
				val.eliteTypes = list.ToArray();
			}
			if (Tier_Gilded_AllowAny)
			{
				val.isAvailable = (EliteRules rules) => Run.instance.stageClearCount + 1 >= Tier_Gilded_StageCount;
			}
			else
			{
				val.isAvailable = (EliteRules rules) => (int)rules == 0 && Run.instance.stageClearCount + 1 >= Tier_Gilded_StageCount;
			}
			val.costMultiplier = Tier_Gilded_Cost;
		}
		EliteTierDef val2 = EliteAPI.VanillaEliteTiers[4];
		if (val2 != null)
		{
			List<EliteDef> list3 = val2.eliteTypes.ToList();
			if (Mod_Perfected_Tier == ConfigAddTo.TierTwo)
			{
				list3.Add(Custom_PerfectedDef);
			}
			if (Mod_Void_Tier == ConfigAddTo.TierTwo)
			{
				list3.Add(Custom_VoidDef);
			}
			if (Gilded_Tier == ConfigAddTo.TierTwo)
			{
				list3.Add(gildedDef);
			}
			val2.eliteTypes = list3.ToArray();
		}
		EliteTierDef val3 = EliteAPI.VanillaEliteTiers[5];
		if (val3 != null)
		{
			val3.costMultiplier = Tier_Lunar_Cost;
		}
	}

	private void UpdateGilded()
	{
		perfectedDef.healthBoostCoefficient = Gilded_Health;
		perfectedDef.damageBoostCoefficient = Gilded_Damage;
	}

	private void UpdatePerfected()
	{
		perfectedDef.healthBoostCoefficient = Lunar_Perfected_Health;
		perfectedDef.damageBoostCoefficient = Lunar_Perfected_Damage;
	}

	private void CreateVoid()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		Custom_VoidDef = ScriptableObject.CreateInstance<EliteDef>();
		((Object)Custom_VoidDef).name = "edVoidTri";
		Custom_VoidDef.modifierToken = voidDef.modifierToken;
		Custom_VoidDef.shaderEliteRampIndex = voidDef.shaderEliteRampIndex;
		Custom_VoidDef.eliteEquipmentDef = voidDef.eliteEquipmentDef;
		Custom_VoidDef.color = voidDef.color;
		Custom_VoidDef.healthBoostCoefficient = Mod_Void_Health;
		Custom_VoidDef.damageBoostCoefficient = Mod_Void_Damage;
		EliteTierDef[] array = (EliteTierDef[])(object)new EliteTierDef[1]
		{
			new EliteTierDef()
		};
		array[0].eliteTypes = (EliteDef[])(object)new EliteDef[1] { Custom_VoidDef };
		CustomElite val = new CustomElite(Custom_VoidDef, (IEnumerable<EliteTierDef>)array);
		EliteAPI.Add(val);
	}

	private void CreatePerfected()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		Custom_PerfectedDef = ScriptableObject.CreateInstance<EliteDef>();
		((Object)Custom_PerfectedDef).name = "edLunarTri";
		Custom_PerfectedDef.modifierToken = perfectedDef.modifierToken;
		Custom_PerfectedDef.shaderEliteRampIndex = perfectedDef.shaderEliteRampIndex;
		Custom_PerfectedDef.eliteEquipmentDef = perfectedDef.eliteEquipmentDef;
		Custom_PerfectedDef.color = perfectedDef.color;
		Custom_PerfectedDef.healthBoostCoefficient = Mod_Perfected_Health;
		Custom_PerfectedDef.damageBoostCoefficient = Mod_Perfected_Damage;
		EliteTierDef[] array = (EliteTierDef[])(object)new EliteTierDef[1]
		{
			new EliteTierDef()
		};
		array[0].eliteTypes = (EliteDef[])(object)new EliteDef[1] { Custom_PerfectedDef };
		CustomElite val = new CustomElite(Custom_PerfectedDef, (IEnumerable<EliteTierDef>)array);
		EliteAPI.Add(val);
	}

	private void ReadConfigs()
	{
		Tier_Lunar_Cost = ((BaseUnityPlugin)this).Config.Bind<float>("Elite Tier - Lunar", "Cost", 6f, "Director cost for spawning. (6 = Vanilla)").Value;
		Lunar_Perfected_Health = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Vanilla Perfected", "Health", 2f, "Health multiplier. (2 = Vanilla) (Get x1.25 Shield from the Aspect)").Value;
		Lunar_Perfected_Damage = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Vanilla Perfected", "Damage", 2f, "Damage multiplier. (2 = Vanilla)").Value;
		Tier_Gilded_AllowAny = ((BaseUnityPlugin)this).Config.Bind<bool>("Elite Tier - Gilded", "Allow Any", false, "Allows most enemies to spawn as this Elite. (True would be closer to T1 Elite behavior, False would be closer to T2 Elite.)").Value;
		Tier_Gilded_Cost = ((BaseUnityPlugin)this).Config.Bind<float>("Elite Tier - Gilded", "Cost", 9f, "Director cost for spawning. (3.5 = Vanilla)").Value;
		Tier_Gilded_StageCount = ((BaseUnityPlugin)this).Config.Bind<int>("Elite Tier - Gilded", "Stage Count", 3, "The minimun stage count that this elite tier becomes active on. (3 = Vanilla)").Value;
		Tier_Gilded_Fix = ((BaseUnityPlugin)this).Config.Bind<bool>("Elite Tier - Gilded", "Fix Tier", true, "Removes Blazing, Glacial, Overloading and Mending from this elite tier.").Value;
		Gilded_Tier = ((BaseUnityPlugin)this).Config.Bind<ConfigAddTo>("Elite - Gilded", "Elite Tier", ConfigAddTo.TierGilded, "Add to which elite pool?").Value;
		Gilded_Health = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Gilded", "Health", 6f, "Health multiplier. (6 = Vanilla)").Value;
		Gilded_Damage = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Gilded", "Damage", 3f, "Damage multiplier. (3 = Vanilla)").Value;
		Mod_Perfected_Tier = ((BaseUnityPlugin)this).Config.Bind<ConfigAddTo>("Elite - Modded Perfected", "Elite Tier", ConfigAddTo.TierTwo, "Add to which elite pool?").Value;
		Mod_Perfected_Health = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Modded Perfected", "Health", 14.4f, "Health multiplier. (2 = Vanilla) (Gets x1.25 Shield from the Aspect)").Value;
		Mod_Perfected_Damage = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Modded Perfected", "Damage", 6f, "Damage multiplier. (2 = Vanilla)").Value;
		Mod_Void_Tier = ((BaseUnityPlugin)this).Config.Bind<ConfigAddTo>("Elite - Voidtouched", "Elite Tier", ConfigAddTo.Disable, "Add to which elite pool?").Value;
		Mod_Void_Health = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Voidtouched", "Health", 1f, "Health multiplier. (Gets x1.5 Health from the Aspect)").Value;
		Mod_Void_Damage = ((BaseUnityPlugin)this).Config.Bind<float>("Elite - Voidtouched", "Damage", 1f, "Damage multiplier. (Gets x0.7 Damage from the Aspect)").Value;
		Director_Enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Elite Director", "Enable", false, "Enables changes to how the Director selects elites to improve diversity. Mostly affects setups with many elite tiers with similar costs.").Value;
	}
}