Decompiled source of DLCSpawnPoolFixer v1.3.3

SotsSpawnPoolFixer.dll

Decompiled a day ago
using System;
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 HG;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.Utils;
using RoR2;
using RoR2.ExpansionManagement;
using RoR2.Navigation;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SotsSpawnPoolFixer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cd4b4260ca97f1c12754ded4357fdad600567f60")]
[assembly: AssemblyProduct("SotsSpawnPoolFixer")]
[assembly: AssemblyTitle("SotsSpawnPoolFixer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SpawnPoolFixer;

public class WConfig
{
	public static ConfigFile ConfigFile = new ConfigFile(Paths.ConfigPath + "\\Wolfo.SpawnPoolFixer.cfg", true);

	public static ConfigEntry<float> cfgStage1Weight;

	public static ConfigEntry<bool> cfgSotV_EnemyRemovals;

	public static ConfigEntry<bool> WORMREMOVAL;

	public static ConfigEntry<bool> cfgLoopSeers;

	public static void InitConfig()
	{
		cfgStage1Weight = ConfigFile.Bind<float>("Config", "Plains Roost weight", 0.75f, "They are counted as 2 stages due to the 2 variants, so they essentially have double the weight.");
		cfgSotV_EnemyRemovals = ConfigFile.Bind<bool>("Config", "SotV enemy removals", true, "SotV replaced various enemies with new enemies.\nThis feature was removed in the new spawn pool system.");
		WORMREMOVAL = ConfigFile.Bind<bool>("Config", "SotV Meadows Worm removal", false, "SotV replaced Magma Worms on Sky Meadows with XI Construct. ");
		cfgLoopSeers = ConfigFile.Bind<bool>("Config", "Remove Pre Loop Destination from Seers during loops", true, "You can get PreLoop variants of stages that have loop variants as Lunar Seer Destinations.\nVanilla : True\nThis was confirmed a funny quirk so it probably wont be removed.\nBut it looks like a bug so this removes it");
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Wolfo.DLCSpawnPoolFixer", "DLCSpawnPoolFixer", "1.3.0")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class SotsSpawnPoolFix : BaseUnityPlugin
{
	public static ExpansionDef DLC1 = Addressables.LoadAssetAsync<ExpansionDef>((object)"RoR2/DLC1/Common/DLC1.asset").WaitForCompletion();

	public void Awake()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		WConfig.InitConfig();
		FixSotsSpawnpools();
		SceneCollection val = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/sgStage1.asset").WaitForCompletion();
		((SceneEntry)(ref val._sceneEntries[0])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val._sceneEntries[1])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val._sceneEntries[2])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val._sceneEntries[3])).weight = WConfig.cfgStage1Weight.Value;
		SceneCollection val2 = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/loopSgStage1.asset").WaitForCompletion();
		((SceneEntry)(ref val2._sceneEntries[0])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val2._sceneEntries[1])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val2._sceneEntries[2])).weight = WConfig.cfgStage1Weight.Value;
		((SceneEntry)(ref val2._sceneEntries[3])).weight = WConfig.cfgStage1Weight.Value;
		SceneDirector.onGenerateInteractableCardSelection += FixWrongRadarTowers;
		ClassicStageInfo.RebuildCards += new Manipulator(SotV_EnemyRemovals);
		BazaarController.IsUnlockedBeforeLooping += new hook_IsUnlockedBeforeLooping(NoPreLoopPostLoop);
		Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"32c40c2b1da4a4244871ef499447ac1a").WaitForCompletion().maxSpawnsPerStage = 1;
		Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"c6c8f501bfa87e54294f9b0bb9db3da4").WaitForCompletion().maxSpawnsPerStage = 1;
		NodeGraph val3 = Addressables.LoadAssetAsync<NodeGraph>((object)"RoR2/DLC1/itancientloft/itancientloft_GroundNodeGraph.asset").WaitForCompletion();
		NodeGraph val4 = Addressables.LoadAssetAsync<NodeGraph>((object)"RoR2/DLC1/itmoon/itmoon_GroundNodeGraph.asset").WaitForCompletion();
		NodeGraph val5 = Addressables.LoadAssetAsync<NodeGraph>((object)"RoR2/DLC1/voidraid/voidraid_GroundNodeGraph.asset").WaitForCompletion();
		for (int i = 0; i < val3.nodes.Length; i++)
		{
			ref NodeFlags flags = ref val3.nodes[i].flags;
			flags = (NodeFlags)((uint)flags | 1u);
		}
		for (int j = 0; j < val4.nodes.Length; j++)
		{
			ref NodeFlags flags2 = ref val4.nodes[j].flags;
			flags2 = (NodeFlags)((uint)flags2 | 1u);
		}
		for (int k = 0; k < val5.nodes.Length; k++)
		{
			ref NodeFlags flags3 = ref val5.nodes[k].flags;
			flags3 = (NodeFlags)((uint)flags3 | 1u);
		}
	}

	private bool NoPreLoopPostLoop(orig_IsUnlockedBeforeLooping orig, BazaarController self, SceneDef sceneDef)
	{
		if (WConfig.cfgLoopSeers.Value && Object.op_Implicit((Object)(object)sceneDef.loopedSceneDef) && Run.instance.stageClearCount >= 5)
		{
			return false;
		}
		return orig.Invoke(self, sceneDef);
	}

	private void SotV_EnemyRemovals(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchStfld(x, "RoR2.ClassicStageInfo", "modifiableMonsterCategories")
		}))
		{
			val.EmitDelegate<Func<DirectorCardCategorySelection, DirectorCardCategorySelection>>((Func<DirectorCardCategorySelection, DirectorCardCategorySelection>)delegate(DirectorCardCategorySelection dccs)
			{
				RemoveMonsterBasedOnSotVReplacement(dccs);
				return dccs;
			});
		}
		else
		{
			Debug.LogWarning((object)"IL Failed: SotV_EnemyRemovals");
		}
	}

	public static void RemoveMonsterBasedOnSotVReplacement(DirectorCardCategorySelection dccs)
	{
		if (!WConfig.cfgSotV_EnemyRemovals.Value || !Object.op_Implicit((Object)(object)Run.instance) || !Run.instance.IsExpansionEnabled(DLC1))
		{
			return;
		}
		switch (SceneInfo.instance.sceneDef.cachedName)
		{
		case "golemplains":
		case "golemplains2":
			RemoveCard(dccs, 2, "fish");
			break;
		case "frozenwall":
			RemoveCard(dccs, 2, "Lemurian");
			RemoveCard(dccs, 2, "Wisp");
			break;
		case "dampcavesimple":
			RemoveCard(dccs, 1, "GreaterWisp");
			break;
		case "shipgraveyard":
			RemoveCard(dccs, 2, "Beetle");
			break;
		case "rootjungle":
			RemoveCard(dccs, 1, "LemurianBruiser");
			RemoveCard(dccs, 2, "Lemurian");
			break;
		case "skymeadow":
			if (WConfig.WORMREMOVAL.Value)
			{
				RemoveCard(dccs, 0, "MagmaWorm");
			}
			break;
		}
	}

	public static void RemoveCard(DirectorCardCategorySelection dccs, int cat, string card)
	{
		Debug.Log((object)("Attempting to remove " + card + " from " + (object)SceneInfo.instance.sceneDef));
		string text = "";
		switch (cat)
		{
		case 2:
			text = "Basic Monsters";
			break;
		case 1:
			text = "Minibosses";
			break;
		case 0:
			text = "Champions";
			break;
		}
		cat = dccs.FindCategoryIndexByName(text);
		if (cat != -1)
		{
			int num = FindSpawnCard(dccs.categories[cat].cards, card);
			if (num != -1)
			{
				ArrayUtils.ArrayRemoveAtAndResize<DirectorCard>(ref dccs.categories[cat].cards, num, 1);
			}
		}
	}

	public static int FindSpawnCard(DirectorCard[] insert, string LookingFor)
	{
		for (int i = 0; i < insert.Length; i++)
		{
			if (((Object)insert[i].spawnCard).name.EndsWith(LookingFor))
			{
				return i;
			}
		}
		Debug.LogWarning((object)("Couldn't find " + LookingFor));
		return -1;
	}

	private void FixWrongRadarTowers(SceneDirector scene, DirectorCardCategorySelection dccs)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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)
		int num = dccs.FindCategoryIndexByName("Rare");
		if (num == -1)
		{
			return;
		}
		Category val = dccs.categories[num];
		for (int i = 0; i < val.cards.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)val.cards[i].forbiddenUnlockableDef))
			{
				string cachedName = SceneInfo.instance.sceneDef.cachedName;
				if (cachedName.StartsWith("habitat"))
				{
					UnlockableDef unlockableDef = UnlockableCatalog.GetUnlockableDef("Logs.Stages." + cachedName);
					Debug.Log((object)("Automatic Radar Scanner fix for " + (object)unlockableDef));
					val.cards[i].forbiddenUnlockableDef = unlockableDef;
				}
				val.cards[i].selectionWeight = 10000;
			}
		}
	}

	public static void FixSotsSpawnpools()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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)
		DccsPool val = Addressables.LoadAssetAsync<DccsPool>((object)"RoR2/DLC2/artifactworld02/dpArtifactWorld02Monsters.asset").WaitForCompletion();
		((PoolEntry)val.poolCategories[0].includedIfConditionsMet[0]).dccs = Addressables.LoadAssetAsync<DirectorCardCategorySelection>((object)"RoR2/DLC2/artifactworld02/dccsArtifactWorld02Monsters_DLC1.asset").WaitForCompletion();
		DirectorCardCategorySelection val2 = Addressables.LoadAssetAsync<DirectorCardCategorySelection>((object)"RoR2/DLC2/village/dccsVillageInteractables_DLC2.asset").WaitForCompletion();
		val2.categories[5].cards[3].minimumStageCompletions = 1;
	}
}