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+456537ce7bf07415f989f8efb4042e2b961d082a")]
[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.0")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class AlloyHunterSurprise : BaseUnityPlugin
{
private const string PluginGUID = "icebro.AlloyHunterSurprise";
private const string PluginAuthor = "icebro";
private const string PluginName = "AlloyHunterSurprise";
private const string PluginVersion = "1.0.0";
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_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Expected O, but got Unknown
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Expected O, but got Unknown
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
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);
AsyncOperationHandle<GameObject> matVultureHunterAddressable = Addressables.LoadAssetAsync<GameObject>((object)RoR2_DLC3_VultureHunter.VultureHunterMaster_prefab);
matVultureHunterAddressable.Completed += delegate
{
alloyHunterMasterOriginalRef = matVultureHunterAddressable.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)
{
alloyHunterMaster = masterPrefab;
return;
}
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 !!");
}
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;
}
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);
}
}
}