Decompiled source of AlloyHunterSurprise v1.0.1

AlloyHunterSurprise.dll

Decompiled a day 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates.VultureHunter.Body;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.Utils;
using RoR2;
using RoR2.EntitlementManagement;
using RoR2.ExpansionManagement;
using RoR2BepInExPack.GameAssetPaths.Version_1_35_0;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;

[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("AlloyHunterSurprise")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b904b917f7a3ae86c3f952fa22c980656994882e")]
[assembly: AssemblyProduct("AlloyHunterSurprise")]
[assembly: AssemblyTitle("AlloyHunterSurprise")]
[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 AlloyHunterSurprise
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("icebro.AlloyHunterSurprise", "AlloyHunterSurprise", "1.0.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class AlloyHunterSurprise : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Manipulator <>9__16_2;

			public static Func<Instruction, bool> <>9__20_0;

			public static Func<Instruction, bool> <>9__20_1;

			public static Func<Instruction, bool> <>9__20_2;

			public static Func<Instruction, bool> <>9__20_3;

			public static Func<Instruction, bool> <>9__20_4;

			public static Func<Instruction, bool> <>9__20_5;

			public static Action<VultureFightOverride> <>9__20_6;

			internal void <Awake>b__16_2(ILContext il)
			{
				Debug.Log((object)"logging ");
				Debug.Log((object)il);
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_0(Instruction x)
			{
				return ILPatternMatchingExt.MatchCall<TeleporterInteraction>(x, "get_instance");
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_1(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<TeleporterInteraction>(x, "bossDirector");
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<VultureFightOverride>(x, "ForcedBossFight");
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_4(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <VultureFightOverrideOnTriggerServer>b__20_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld<VultureFightOverride>(x, "singularScaledBoss");
			}

			internal void <VultureFightOverrideOnTriggerServer>b__20_6(VultureFightOverride vultureOverride)
			{
				if (vultureOverride.ForcedBossFight != null)
				{
					TeleporterInteraction.instance.bossDirector.OverrideNextBossCard(vultureOverride.ForcedBossFight, vultureOverride.singularScaledBoss && (!Object.op_Implicit((Object)(object)TeleporterInteraction.instance) || TeleporterInteraction.instance.shrineBonusStacks <= 0));
				}
			}
		}

		private const string PluginGUID = "icebro.AlloyHunterSurprise";

		private const string PluginAuthor = "icebro";

		private const string PluginName = "AlloyHunterSurprise";

		private const string PluginVersion = "1.0.1";

		private GameObject alloyHunterMasterOriginalRef;

		private GameObject alloyHunterMaster;

		private ConfigEntry<float> invasionChance;

		private ConfigEntry<int> minStageCount;

		private ConfigEntry<string> invaderReplacement;

		private ConfigEntry<float> healthPercent;

		private ConfigEntry<bool> asManyInvasionsAsBosses;

		private ConfigEntry<bool> dontInvadeHordes;

		private ConfigEntry<string> invasionWhitelist;

		private List<string> invasionWhitelistReal = new List<string>();

		private static bool UHRInstalled => Chainloader.PluginInfos.ContainsKey("iDeathHD.UnityHotReload");

		public void Awake()
		{
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			invasionChance = ((BaseUnityPlugin)this).Config.Bind<float>("AlloyHunterSurprise", "invasion chance.,.,.,", 30f, "chance for alloy hunter to invade (0-100% .,.,");
			minStageCount = ((BaseUnityPlugin)this).Config.Bind<int>("AlloyHunterSurprise", "minimum stage count,..,.,", 3, "chance for alloy hunter to invade (0-100% .,.,");
			invaderReplacement = ((BaseUnityPlugin)this).Config.Bind<string>("AlloyHunterSurprise", "invader replacement !! put master name ,. (eg. BrotherMaster", "", "itsl ike !! what autocompletes when doing spawn_ai .,., leave blank for no replacement!!");
			invaderReplacement.SettingChanged += delegate
			{
				replaceInvader();
			};
			invasionWhitelist = ((BaseUnityPlugin)this).Config.Bind<string>("AlloyHunterSurprise", "invasion whitelist !! seperate with comma ,.,.", "RoboBallBossMaster,SolusAmalgamatorMaster", "get from spawn_ai autocompletes !! eg. (RoboBallBossMaster,SolusAmalgamatorMaster)!!");
			UpdateWhitelist();
			invasionWhitelist.SettingChanged += delegate
			{
				UpdateWhitelist();
			};
			asManyInvasionsAsBosses = ((BaseUnityPlugin)this).Config.Bind<bool>("AlloyHunterSurprise", "have as many invasions as spawned bosses,.,.", false, "like !! if theres multiple bosses have mutliple invasion .,.,");
			dontInvadeHordes = ((BaseUnityPlugin)this).Config.Bind<bool>("AlloyHunterSurprise", "dont invade hordes of many,..,", true, "explanitory i think.,,. .,.,");
			healthPercent = ((BaseUnityPlugin)this).Config.Bind<float>("AlloyHunterSurprise", "health percentage before steal !!!", 0.75f, "health threshold before killing !!!!");
			TeleporterInteraction.Awake += new hook_Awake(TeleporterInteractionOnAwake);
			VultureFightOverride.TriggerVultureOnMasterServer += new hook_TriggerVultureOnMasterServer(VultureFightOverrideOnTriggerVultureOnMasterServer);
			VultureFightOverride.TriggerServer += new Manipulator(VultureFightOverrideOnTriggerServer);
			MasterCatalog.Init += new hook_Init(MasterCatalogOnInit);
			object obj = <>c.<>9__16_2;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					Debug.Log((object)"logging ");
					Debug.Log((object)il);
				};
				<>c.<>9__16_2 = val;
				obj = (object)val;
			}
			VultureFightOverride.TriggerVultureOnMasterServer += (Manipulator)obj;
			AsyncOperationHandle<GameObject> val2 = Addressables.LoadAssetAsync<GameObject>((object)RoR2_DLC3_VultureHunter.VultureHunterMaster_prefab);
			val2.Completed += delegate(AsyncOperationHandle<GameObject> result)
			{
				alloyHunterMasterOriginalRef = result.Result;
			};
		}

		private void UpdateWhitelist()
		{
			invasionWhitelistReal = new List<string>();
			string[] array = invasionWhitelist.Value.Split(",");
			foreach (string text in array)
			{
				if (!Utility.IsNullOrWhiteSpace(text.Trim()))
				{
					invasionWhitelistReal.Add(text.Trim());
				}
			}
		}

		private void MasterCatalogOnInit(orig_Init orig)
		{
			orig.Invoke();
			replaceInvader();
		}

		private void replaceInvader()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			GameObject masterPrefab = MasterCatalog.GetMasterPrefab(MasterCatalog.FindMasterIndex(invaderReplacement.Value));
			if ((Object)(object)masterPrefab != (Object)null)
			{
				Log.Debug($"replacing invader with {masterPrefab} !!");
				alloyHunterMaster = masterPrefab;
			}
			else
			{
				Log.Debug("failed to find invader " + invaderReplacement.Value + ",.., falling back on alloyhunter !!");
				alloyHunterMaster = alloyHunterMasterOriginalRef;
			}
		}

		private void VultureFightOverrideOnTriggerServer(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext(new Func<Instruction, bool>[6]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<TeleporterInteraction>(x, "get_instance"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<TeleporterInteraction>(x, "bossDirector"),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<VultureFightOverride>(x, "ForcedBossFight"),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<VultureFightOverride>(x, "singularScaledBoss")
			}))
			{
				return;
			}
			val.RemoveRange(13);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<VultureFightOverride>>((Action<VultureFightOverride>)delegate(VultureFightOverride vultureOverride)
			{
				if (vultureOverride.ForcedBossFight != null)
				{
					TeleporterInteraction.instance.bossDirector.OverrideNextBossCard(vultureOverride.ForcedBossFight, vultureOverride.singularScaledBoss && (!Object.op_Implicit((Object)(object)TeleporterInteraction.instance) || TeleporterInteraction.instance.shrineBonusStacks <= 0));
				}
			});
			Log.Debug("added il hook to null chcek forcedbossfight !!");
			Debug.Log((object)il);
		}

		private void VultureFightOverrideOnTriggerVultureOnMasterServer(orig_TriggerVultureOnMasterServer orig, VultureFightOverride self, CharacterMaster boss)
		{
			if (self.singularKiller && Reflection.GetFieldValue<int>((object)self, "bossReplacementsPerformed") > 0)
			{
				return;
			}
			if (self.ForcedBossFight == null)
			{
				WeightedSelection<DirectorCard> monsterSelection = ClassicStageInfo.instance.monsterSelection;
				DirectorCard forcedBossFight = null;
				CharacterBody val = default(CharacterBody);
				for (int i = 0; i < monsterSelection._count; i++)
				{
					DirectorCard value = monsterSelection.choices[i].value;
					object obj;
					if (value == null)
					{
						obj = null;
					}
					else
					{
						SpawnCard spawnCard = value.spawnCard;
						if (spawnCard == null)
						{
							obj = null;
						}
						else
						{
							GameObject prefab = spawnCard.prefab;
							obj = ((prefab == null) ? null : prefab.GetComponent<CharacterMaster>()?.bodyPrefab);
						}
					}
					if (!((Object)obj != (Object)(object)boss?.bodyPrefab))
					{
						forcedBossFight = monsterSelection.choices[i].value;
						Log.Debug("found " + ((Object)boss).name + " s card !!! ");
						if (((Object)boss).name.Contains("RoboBallBoss") || ((Object)boss).name.Contains("SolusAmalgamator"))
						{
							SpawnAfterMuder.idleAfterTeleportDelay = 1.85f;
							DoMurder.enterDelay = 5.5f;
							self.healthbarHideDuration = 6.2f;
						}
						else
						{
							SpawnAfterMuder.idleAfterTeleportDelay = 1f;
							DoMurder.enterDelay = 3f;
							self.healthbarHideDuration = 4f;
						}
						if ((!dontInvadeHordes.Value || !Object.op_Implicit((Object)(object)boss.bodyPrefab) || !boss.bodyPrefab.TryGetComponent<CharacterBody>(ref val) || val.isChampion) && (invasionWhitelistReal.Count == 0 || invasionWhitelistReal.Contains(((Object)boss).name.Replace("(Clone)", ""))))
						{
							break;
						}
						self.watchingSquadMembers.Remove(boss);
						if (self.watchingSquadMembers.Count == 0)
						{
							TeleporterInteraction.instance.bossDirector.combatSquad.delayDefeat = false;
						}
						return;
					}
				}
				self.ForcedBossFight = forcedBossFight;
			}
			Log.Debug($" forced fight null ? {self.ForcedBossFight == null}");
			if (self.ForcedBossFight != null)
			{
				orig.Invoke(self, boss);
			}
		}

		private void TeleporterInteractionOnAwake(orig_Awake orig, TeleporterInteraction self)
		{
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)((Component)self).gameObject.GetComponent<VultureFightOverride>()))
			{
				SpawnAfterMuder.idleAfterTeleportDelay = 1.85f;
				DoMurder.enterDelay = 5f;
			}
			else if (NetworkServer.active && Run.instance.runRNG.RangeFloat(0f, 100f) <= invasionChance.Value && Run.instance.stageClearCount + 1 >= minStageCount.Value)
			{
				VultureFightOverride val = ((Component)self).gameObject.AddComponent<VultureFightOverride>();
				val.singularKiller = !asManyInvasionsAsBosses.Value;
				val.triggerOnStart = true;
				val.nextKillSequenceMin = 2f;
				val.nextKillSequenceMax = 5f;
				val.healthbarHideDuration = 4f;
				val.replacementAtHealthThreshold = healthPercent.Value;
				val.replacementMaster = alloyHunterMaster;
				CharacterMaster val2 = default(CharacterMaster);
				CharacterBody val3 = default(CharacterBody);
				ExpansionRequirementComponent val4 = default(ExpansionRequirementComponent);
				if (alloyHunterMaster.TryGetComponent<CharacterMaster>(ref val2) && val2.bodyPrefab.TryGetComponent<CharacterBody>(ref val3) && ((Component)val3).TryGetComponent<ExpansionRequirementComponent>(ref val4) && !((BaseUserEntitlementTracker<NetworkUser>)(object)EntitlementManager.networkUserEntitlementTracker).AnyUserHasEntitlement(val4.requiredExpansion.requiredEntitlement))
				{
					Log.Debug("user doesnt have any entitlement !!! gorp ,,.,. get the dlc of whatever youre trying to spawn silly <//3..,.,");
					Object.Destroy((Object)(object)val);
				}
			}
		}
	}
	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);
		}
	}
}