using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HG.Reflection;
using On.RoR2;
using RoR2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BossAntiSoftlock")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d78d64868e72e1bd6d45d0be919f2e65f3b4808b")]
[assembly: AssemblyProduct("BossAntiSoftlock")]
[assembly: AssemblyTitle("BossAntiSoftlock")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BossAntiSoftlock;
[BepInPlugin("com.justinderby.bossantisoftlock", "Boss Anti-Softlock", "1.0.5")]
public class BossAntiSoftlock : BaseUnityPlugin
{
public const string GUID = "com.justinderby.bossantisoftlock";
public const string ModName = "Boss Anti-Softlock";
public const string Version = "1.0.5";
public static Dictionary<CharacterBody, Vector3> SpawnPositions = new Dictionary<CharacterBody, Vector3>();
public static ConfigFile Configuration;
public static ConfigEntry<bool> ModHint;
public static ConfigEntry<bool> ResetVoid;
public static BossAntiSoftlock Instance;
public void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Expected O, but got Unknown
Instance = SingletonHelper.Assign<BossAntiSoftlock>(Instance, this);
Configuration = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.justinderby.bossantisoftlock.cfg"), true);
ModHint = Configuration.Bind<bool>("General", "Show Hints", true, "Whether to send a reminder every time the teleporter event has started.");
ResetVoid = Configuration.Bind<bool>("General", "Reset Voidtouched Monsters", true, "Whether to also reset voidtouched monsters.");
Stage.onStageStartGlobal += delegate
{
SpawnPositions.Clear();
};
Run.OnServerCharacterBodySpawned += new hook_OnServerCharacterBodySpawned(TrackNewMonster);
GlobalEventManager.onCharacterDeathGlobal += RemoveMonster;
TeleporterInteraction.onTeleporterBeginChargingGlobal += SendModHint;
Console.RunCmd += new hook_RunCmd(HandleCommand);
}
public void Destroy()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
Instance = null;
Stage.onStageStartGlobal -= delegate
{
SpawnPositions.Clear();
};
Run.OnServerCharacterBodySpawned -= new hook_OnServerCharacterBodySpawned(TrackNewMonster);
GlobalEventManager.onCharacterDeathGlobal -= RemoveMonster;
TeleporterInteraction.onTeleporterBeginChargingGlobal -= SendModHint;
Console.RunCmd -= new hook_RunCmd(HandleCommand);
SpawnPositions.Clear();
}
private void SendModChat(string message)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
{
baseToken = "<color=#93c47d>Boss Anti-Softlock:</color> " + message
});
}
[ConCommand(/*Could not decode attribute arguments.*/)]
private static void ForceResetPositions(ConCommandArgs _)
{
if (Object.op_Implicit((Object)(object)Instance))
{
Debug.Log((object)"Resetting all monster positions...");
Instance.ResetCharactersPositions(GetBosses());
}
}
private void HandleCommand(orig_RunCmd orig, Console self, CmdSender sender, string concommandName, List<string> userArgs)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(self, sender, concommandName, userArgs);
if (!concommandName.Equals("say", StringComparison.InvariantCultureIgnoreCase) || userArgs.Count == 0)
{
return;
}
string text = userArgs[0];
switch (text.ToLower())
{
case "/bossreset":
case "/boss_reset":
case "/resetboss":
case "/resetbosses":
case "/reset_boss":
case "/reset_bosses":
case "/br":
case "/rb":
{
List<CharacterBody> bosses = GetBosses();
SendModChat(string.Format("Resetting monster positions... ({0} monster{1})", bosses.Count, (bosses.Count == 1) ? "" : "s"));
try
{
ResetCharactersPositions(bosses);
break;
}
catch (Exception ex)
{
Debug.LogException(ex);
SendModChat("Error resetting boss positions; check console for more info!");
break;
}
}
}
}
private void SendModHint(TeleporterInteraction obj)
{
if (ModHint.Value)
{
SendModChat("Type '/bossreset' to reset monster positions.");
}
}
private void TrackNewMonster(orig_OnServerCharacterBodySpawned orig, Run self, CharacterBody body)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(self, body);
if (!((Object)(object)((Component)body).gameObject == (Object)null) && ((Behaviour)body).isActiveAndEnabled && !body.isPlayerControlled)
{
SpawnPositions.Add(body, body.footPosition);
}
}
private static List<CharacterBody> GetBosses()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Invalid comparison between Unknown and I4
List<CharacterBody> list = new List<CharacterBody>();
foreach (CharacterBody key in SpawnPositions.Keys)
{
if (!((Object)(object)((key != null) ? ((Component)key).gameObject : null) == (Object)null) && ((Behaviour)key).isActiveAndEnabled && (key.isBoss || Run.instance is InfiniteTowerRun || (ResetVoid.Value && (int)key.teamComponent.teamIndex == 4)))
{
list.Add(key);
}
}
return list;
}
private void RemoveMonster(DamageReport report)
{
if ((Object)(object)report?.victimBody != (Object)null)
{
SpawnPositions.Remove(report.victimBody);
}
}
private void ResetCharactersPositions(List<CharacterBody> bodies)
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
if (ResetVoid.Value)
{
foreach (TeamComponent teamMember in TeamComponent.GetTeamMembers((TeamIndex)4))
{
if ((Object)(object)teamMember.body != (Object)null && !bodies.Contains(teamMember.body))
{
bodies.Add(teamMember.body);
}
}
}
foreach (CharacterBody body in bodies)
{
if ((Object)(object)body == (Object)null || (Object)(object)((Component)body).gameObject == (Object)null || !((Behaviour)body).isActiveAndEnabled)
{
SpawnPositions.Remove(body);
continue;
}
Debug.Log((object)string.Format("{0} - Teleporting {1} to {2}", "com.justinderby.bossantisoftlock", body, SpawnPositions[body]));
TeleportHelper.TeleportBody(body, SpawnPositions[body]);
GameObject gameObject = ((Component)body).gameObject;
if (Object.op_Implicit((Object)(object)gameObject))
{
EntityStateMachine[] components = gameObject.GetComponents<EntityStateMachine>();
foreach (EntityStateMachine val in components)
{
val.initialStateType = val.mainStateType;
}
GameObject teleportEffectPrefab = Run.instance.GetTeleportEffectPrefab(gameObject.gameObject);
if (Object.op_Implicit((Object)(object)teleportEffectPrefab))
{
EffectManager.SimpleEffect(teleportEffectPrefab, SpawnPositions[body], Quaternion.identity, true);
}
}
}
}
}