Decompiled source of MyRogueTeamROR2ModPlugin v1.0.3

BepInEx/Plugins/RogueTeamPlugin.dll

Decompiled 2 weeks ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using R2API;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Navigation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RogueTeamPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RogueTeamPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a4c09232-17b4-460d-9533-44d54f380794")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RogueTeamPlugin
{
	public class NewFriendsAchievement : ModdedUnlockable
	{
		public const string AchievementId = "ROGUE_NEWFRIENDS_ACHIEVEMENT_ID";

		public const string UnlockableId = "ROGUE_NEWFRIENDS_UNLOCKABLE_ID";

		public override string AchievementIdentifier => "ROGUE_NEWFRIENDS_ACHIEVEMENT_ID";

		public override string UnlockableIdentifier => "ROGUE_NEWFRIENDS_UNLOCKABLE_ID";

		public override string AchievementNameToken => "NEW_FRIENDS_ACHIEVEMENT_NAME";

		public override string AchievementDescToken => "NEW_FRIENDS_ACHIEVEMENT_DESC";

		public override string UnlockableNameToken => "NEW_FRIENDS_UNLOCKABLE_NAME";

		public override Sprite Sprite => null;

		public override string PrerequisiteUnlockableIdentifier => "";

		public override Func<string> GetHowToUnlock => () => "Escape the planet with the Rogue faction enabled.";

		public override Func<string> GetUnlocked => () => "You escaped the planet with Rogue allies.";
	}
	public static class RogueArtifact
	{
		public static ArtifactDef Artifact;

		public static bool Enabled
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)RunArtifactManager.instance))
				{
					return false;
				}
				return RunArtifactManager.instance.IsArtifactEnabled(Artifact);
			}
		}

		public static void Init()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			Artifact = ScriptableObject.CreateInstance<ArtifactDef>();
			Artifact.cachedName = "ArtifactOfTheRogue";
			Artifact.nameToken = "ARTIFACT_ROGUE_NAME";
			Artifact.descriptionToken = "ARTIFACT_ROGUE_DESC";
			Artifact.smallIconSelectedSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/texArtifactEnabled.png").WaitForCompletion();
			Artifact.smallIconDeselectedSprite = Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/texArtifactDisabled.png").WaitForCompletion();
			Artifact.pickupModelPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/ArtifactShell.prefab").WaitForCompletion();
			Artifact.unlockableDef = null;
			LanguageAPI.Add("ARTIFACT_ROGUE_NAME", "Artifact of the Rogue");
			LanguageAPI.Add("ARTIFACT_ROGUE_DESC", "Enables the Rogue Team.");
			ArtifactCatalog.getAdditionalEntries += delegate(List<ArtifactDef> list)
			{
				if (!list.Contains(Artifact))
				{
					list.Add(Artifact);
				}
			};
			Debug.Log((object)"[Rogue] ArtifactOfTheRogue registered.");
		}
	}
	public static class RogueDebug
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CC_RogueDebug(ConCommandArgs args)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)RogueDirector.instance == (Object)null)
			{
				Debug.Log((object)"[RogueDebug] RogueDirector is NULL.");
				return;
			}
			RogueDirector instance = RogueDirector.instance;
			Debug.Log((object)"=== ROGUE DIRECTOR DEBUG ===");
			Debug.Log((object)$"Initial Spawn Done: {instance.InitialSpawnDone}");
			Debug.Log((object)$"Is First Stage: {instance.IsFirstStage}");
			Debug.Log((object)$"Max Rogues: {instance.MaxRogues}");
			Debug.Log((object)$"Alive Rogues: {instance.AliveCount}");
			Debug.Log((object)$"Reinforcement Timer: {instance.ReinforcementTimer:F1} / 300");
			Debug.Log((object)("Leader: " + instance.LeaderName));
			Debug.Log((object)$"Has Leader: {instance.HasLeader}");
			Debug.Log((object)"--- Squad ---");
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			Debug.Log((object)$"Squad Members: {orCreateSquad.Members.Count}");
			Debug.Log((object)("Squad Leader: " + (Object.op_Implicit((Object)(object)orCreateSquad.Leader) ? ((Object)orCreateSquad.Leader).name : "None")));
			Debug.Log((object)"--- Last Spawn Info ---");
			Debug.Log((object)$"Last Spawn Success: {instance.LastSpawnSuccess}");
			Debug.Log((object)$"Last Spawn Position: {instance.LastSpawnPosition}");
			Debug.Log((object)"--- Node Selection ---");
			Debug.Log((object)$"Last Node Distance Threshold Used: {instance.LastNodeThreshold}");
			Debug.Log((object)$"Last Node Found: {instance.LastNodeFound}");
			Debug.Log((object)$"Last Node Position: {instance.LastNodePosition}");
			Debug.Log((object)"=== END DEBUG ===");
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CC_RogueDebugVerbose(ConCommandArgs args)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CC_RogueDebug(args);
			if ((Object)(object)RogueDirector.instance == (Object)null)
			{
				return;
			}
			RogueDirector instance = RogueDirector.instance;
			Debug.Log((object)"=== VERBOSE ===");
			Debug.Log((object)"--- Rogue Masters ---");
			foreach (CharacterMaster rogueMaster in instance.RogueMasters)
			{
				if (Object.op_Implicit((Object)(object)rogueMaster))
				{
					CharacterBody body = rogueMaster.GetBody();
					Debug.Log((object)$"Master: {((Object)rogueMaster).name}, Alive: {Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive}");
				}
			}
			Debug.Log((object)"--- Survivors (Persistence) ---");
			if ((Object)(object)RoguePersistence.instance != (Object)null)
			{
				foreach (CharacterMaster survivor in RoguePersistence.instance.SurvivorList)
				{
					Debug.Log((object)("Survivor: " + ((Object)survivor).name));
				}
			}
			Debug.Log((object)"=== END VERBOSE ===");
		}
	}
	public class RogueDirector : MonoBehaviour
	{
		public static RogueDirector instance;

		private const float ReinforcementInterval = 300f;

		private static readonly float[] DistanceThresholds = new float[3] { 60f, 40f, 20f };

		private int maxRogues;

		private bool initialSpawnDone;

		private bool isFirstStage;

		private float reinforcementTimer;

		private readonly List<CharacterMaster> rogueMasters = new List<CharacterMaster>();

		private CharacterMaster leaderMaster;

		public bool LastSpawnSuccess { get; private set; }

		public Vector3 LastSpawnPosition { get; private set; }

		public float LastNodeThreshold { get; private set; }

		public bool LastNodeFound { get; private set; }

		public Vector3 LastNodePosition { get; private set; }

		public bool InitialSpawnDone => initialSpawnDone;

		public bool IsFirstStage => isFirstStage;

		public int MaxRogues => maxRogues;

		public float ReinforcementTimer => reinforcementTimer;

		public int AliveCount => CountAliveRogues();

		public bool HasLeader => (Object)(object)leaderMaster != (Object)null;

		public string LeaderName => Object.op_Implicit((Object)(object)leaderMaster) ? ((Object)leaderMaster).name : "None";

		public IReadOnlyList<CharacterMaster> RogueMasters => rogueMasters;

		public static void Init()
		{
			SceneDirector.onPrePopulateSceneServer += OnSceneStart;
		}

		public static void ClearRogues()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)instance))
			{
				Debug.Log((object)"[Rogue][DEBUG] ClearRogues called. Clearing rogueMasters and squad.");
				instance.rogueMasters.Clear();
				instance.leaderMaster = null;
				RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
				orCreateSquad.Members.Clear();
				orCreateSquad.SetLeader(null);
			}
		}

		public static void RegisterExistingRogue(CharacterMaster master)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)master))
			{
				if (!Object.op_Implicit((Object)(object)instance))
				{
					Debug.LogWarning((object)"[Rogue][DEBUG] RegisterExistingRogue called but RogueDirector is null.");
				}
				else if (!instance.rogueMasters.Contains(master))
				{
					Debug.Log((object)("[Rogue][DEBUG] RegisterExistingRogue: " + ((Object)master).name));
					instance.rogueMasters.Add(master);
					instance.RefreshLeaderFromSquad();
					RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
					orCreateSquad.AddMember(master);
				}
			}
		}

		private static void OnSceneStart(SceneDirector sceneDirector)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			if (!RogueArtifact.Enabled)
			{
				Debug.Log((object)"[Rogue][DEBUG] RogueArtifact disabled. RogueDirector will not initialize this stage.");
				return;
			}
			SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
			if (!Object.op_Implicit((Object)(object)sceneDefForCurrentScene) || (int)sceneDefForCurrentScene.sceneType != 1)
			{
				Debug.Log((object)("[Rogue][DEBUG] Scene is not a Stage. RogueDirector not created. sceneDef=" + (Object.op_Implicit((Object)(object)sceneDefForCurrentScene) ? sceneDefForCurrentScene.cachedName : "null")));
				return;
			}
			if (!Object.op_Implicit((Object)(object)instance))
			{
				GameObject val = new GameObject("RogueDirector");
				instance = val.AddComponent<RogueDirector>();
				Object.DontDestroyOnLoad((Object)(object)val);
				Debug.Log((object)("[Rogue] RogueDirector created for stage: " + sceneDefForCurrentScene.cachedName));
			}
			int num = (Object.op_Implicit((Object)(object)Run.instance) ? Run.instance.stageClearCount : 0);
			instance.ConfigureForStage(num);
			Debug.Log((object)("[Rogue] RogueDirector activated for stage: " + sceneDefForCurrentScene.cachedName + ", " + $"stageIndex={num}, maxRogues={instance.maxRogues}, isFirstStage={instance.isFirstStage}"));
		}

		private void ConfigureForStage(int stageIndex)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			maxRogues = 6 + stageIndex * 2;
			isFirstStage = stageIndex == 0;
			initialSpawnDone = false;
			reinforcementTimer = 0f;
			rogueMasters.Clear();
			leaderMaster = null;
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			orCreateSquad.Members.Clear();
			orCreateSquad.SetLeader(null);
		}

		private void FixedUpdate()
		{
			if (!Object.op_Implicit((Object)(object)Run.instance))
			{
				return;
			}
			PruneRogueList();
			RefreshLeaderFromSquad();
			float fixedDeltaTime = Time.fixedDeltaTime;
			if (!initialSpawnDone)
			{
				if (isFirstStage)
				{
					Debug.Log((object)"[Rogue][DEBUG] InitialSpawn: First stage, spawning immediately.");
					TryInitialSpawnFromPlayer();
					initialSpawnDone = true;
					reinforcementTimer = 0f;
					return;
				}
				reinforcementTimer += fixedDeltaTime;
				if (reinforcementTimer >= 300f)
				{
					Debug.Log((object)"[Rogue][DEBUG] InitialSpawn: Delayed stage, spawning after interval.");
					TryInitialSpawnFromPlayer();
					initialSpawnDone = true;
					reinforcementTimer = 0f;
				}
			}
			else
			{
				reinforcementTimer += fixedDeltaTime;
				if (reinforcementTimer >= 300f)
				{
					reinforcementTimer = 0f;
					Debug.Log((object)"[Rogue][DEBUG] Reinforcement timer elapsed. Trying reinforcement spawn.");
					TrySpawnReinforcement();
				}
			}
		}

		private void TryInitialSpawnFromPlayer()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Vector3? anyPlayerPosition = GetAnyPlayerPosition();
			if (!anyPlayerPosition.HasValue)
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] TryInitialSpawnFromPlayer: No player found for initial Rogue spawn.");
				return;
			}
			Vector3 value = anyPlayerPosition.Value;
			Debug.Log((object)("[Rogue][DEBUG] TryInitialSpawnFromPlayer: Using player position " + ((object)(Vector3)(ref value)).ToString()));
			EnsureRogueCount(anyPlayerPosition.Value);
		}

		private void TrySpawnReinforcement()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			int num = CountAliveRogues();
			if (num >= maxRogues)
			{
				Debug.Log((object)("[Rogue][DEBUG] TrySpawnReinforcement: AliveRogues=" + num + " >= maxRogues=" + maxRogues + ". Skipping."));
			}
			else
			{
				Vector3? val = GetLeaderPosition() ?? GetAnyRoguePosition() ?? GetAnyPlayerPosition();
				if (val.HasValue)
				{
					Vector3 value = val.Value;
					Debug.Log((object)("[Rogue][DEBUG] TrySpawnReinforcement: Anchor position " + ((object)(Vector3)(ref value)).ToString()));
					SpawnSingleRogueAtAnchor(val.Value);
				}
				else
				{
					Debug.LogWarning((object)"[Rogue][DEBUG] TrySpawnReinforcement: No valid anchor found (no leader/rogue/player).");
				}
			}
		}

		private void EnsureRogueCount(Vector3 anchor)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = maxRogues * 2;
			Debug.Log((object)("[Rogue][DEBUG] EnsureRogueCount: Starting. CurrentAlive=" + CountAliveRogues() + " target=" + maxRogues));
			while (CountAliveRogues() < maxRogues && num < num2)
			{
				bool flag = SpawnSingleRogueAtAnchor(anchor);
				Debug.Log((object)("[Rogue][DEBUG] EnsureRogueCount: SpawnRequested=" + flag + " attempts=" + num + " alive=" + CountAliveRogues()));
				if (!flag)
				{
					break;
				}
				num++;
			}
			if (num >= num2)
			{
				Debug.LogWarning((object)("[Rogue] Spawn loop aborted to prevent freeze. attempts=" + num));
			}
		}

		private bool SpawnSingleRogueAtAnchor(Vector3 anchor)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)DirectorCore.instance))
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] SpawnSingleRogueAtAnchor: DirectorCore.instance is NULL.");
				return false;
			}
			if ((Object)(object)RogueSpawnCard.RogueCard == (Object)null)
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] SpawnSingleRogueAtAnchor: RogueSpawnCard.RogueCard is NULL.");
				return false;
			}
			if (!TryGetSpawnPositionFarFrom(anchor, out var position))
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] SpawnSingleRogueAtAnchor: Failed to find spawn position.");
				return false;
			}
			LastSpawnSuccess = false;
			LastSpawnPosition = position;
			Vector3 val = position;
			Debug.Log((object)("[Rogue][DEBUG] SpawnSingleRogueAtAnchor: Attempting spawn at " + ((object)(Vector3)(ref val)).ToString()));
			DirectorSpawnRequest val2 = new DirectorSpawnRequest((SpawnCard)(object)RogueSpawnCard.RogueCard, new DirectorPlacementRule
			{
				placementMode = (PlacementMode)0,
				position = position
			}, RoR2Application.rng);
			val2.teamIndexOverride = RogueTeamPlugin.RogueTeam;
			val2.onSpawnedServer = (Action<SpawnResult>)Delegate.Combine(val2.onSpawnedServer, new Action<SpawnResult>(OnRogueSpawnedServer));
			DirectorCore.instance.TrySpawnObject(val2);
			return true;
		}

		private void OnRogueSpawnedServer(SpawnResult result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if (!result.success || !Object.op_Implicit((Object)(object)result.spawnedInstance))
			{
				Debug.LogWarning((object)("[Rogue][DEBUG] OnRogueSpawnedServer: SpawnResult FAILED. success=" + result.success + " spawnedInstance=" + (object)result.spawnedInstance));
				return;
			}
			LastSpawnSuccess = true;
			CharacterMaster component = result.spawnedInstance.GetComponent<CharacterMaster>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] OnRogueSpawnedServer: Spawned instance has NO CharacterMaster.");
				return;
			}
			string name = ((Object)component).name;
			TeamIndex teamIndex = component.teamIndex;
			Debug.Log((object)("[Rogue][DEBUG] OnRogueSpawnedServer: Spawned Rogue Master=" + name + " | team(before)=" + ((object)(TeamIndex)(ref teamIndex)).ToString()));
			component.teamIndex = RogueTeamPlugin.RogueTeam;
			CharacterBody body = component.GetBody();
			if (Object.op_Implicit((Object)(object)body))
			{
				if (Object.op_Implicit((Object)(object)body.teamComponent))
				{
					body.teamComponent.teamIndex = RogueTeamPlugin.RogueTeam;
				}
				string name2 = ((Object)body).name;
				object obj;
				if (!Object.op_Implicit((Object)(object)body.teamComponent))
				{
					obj = "no TeamComponent";
				}
				else
				{
					teamIndex = body.teamComponent.teamIndex;
					obj = ((object)(TeamIndex)(ref teamIndex)).ToString();
				}
				Debug.Log((object)("[Rogue][DEBUG] OnRogueSpawnedServer: Rogue Body=" + name2 + " | team=" + (string?)obj));
			}
			else
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] OnRogueSpawnedServer: Spawned Rogue has NO BODY yet.");
			}
			if (!rogueMasters.Contains(component))
			{
				rogueMasters.Add(component);
				Debug.Log((object)("[Rogue][DEBUG] OnRogueSpawnedServer: Added master to rogueMasters list. Count=" + rogueMasters.Count));
			}
			else
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] OnRogueSpawnedServer: Master already existed in rogueMasters list.");
			}
			RefreshLeaderFromSquad();
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			orCreateSquad.AddMember(component);
			Debug.Log((object)"[Rogue][DEBUG] OnRogueSpawnedServer: Rogue fully registered into squad.");
		}

		private bool TryGetSpawnPositionFarFrom(Vector3 anchor, out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			position = anchor;
			SceneInfo val = SceneInfo.instance;
			if (!Object.op_Implicit((Object)(object)val))
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] TryGetSpawnPositionFarFrom: SceneInfo.instance is NULL.");
				return false;
			}
			NodeGraph nodeGraph = val.GetNodeGraph((GraphType)0);
			if (!Object.op_Implicit((Object)(object)nodeGraph))
			{
				Debug.LogWarning((object)"[Rogue][DEBUG] TryGetSpawnPositionFarFrom: Ground NodeGraph is NULL.");
				return false;
			}
			float[] distanceThresholds = DistanceThresholds;
			Vector3 val2;
			for (int i = 0; i < distanceThresholds.Length; i++)
			{
				float minDistance = distanceThresholds[i];
				if (TryFindNodeWithMinDistance(nodeGraph, anchor, minDistance, out position))
				{
					val2 = position;
					Debug.Log((object)("[Rogue][DEBUG] TryGetSpawnPositionFarFrom: Found node at " + ((object)(Vector3)(ref val2)).ToString() + " with minDistance=" + minDistance));
					return true;
				}
				Debug.Log((object)("[Rogue][DEBUG] TryGetSpawnPositionFarFrom: No node found for threshold " + minDistance));
			}
			if (TryFindAnyValidNode(nodeGraph, out position))
			{
				val2 = position;
				Debug.Log((object)("[Rogue][DEBUG] TryGetSpawnPositionFarFrom: Using ANY valid node fallback at " + ((object)(Vector3)(ref val2)).ToString()));
				return true;
			}
			Debug.LogWarning((object)"[Rogue][DEBUG] TryGetSpawnPositionFarFrom: Failed to find ANY valid node.");
			return false;
		}

		private bool TryFindNodeWithMinDistance(NodeGraph graph, Vector3 anchor, float minDistance, out Vector3 position)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			position = anchor;
			bool flag = false;
			int nodeCount = graph.GetNodeCount();
			NodeIndex val = default(NodeIndex);
			Vector3 val2 = default(Vector3);
			NodeFlags flags = default(NodeFlags);
			for (int i = 0; i < nodeCount; i++)
			{
				((NodeIndex)(ref val))..ctor(i);
				if (graph.GetNodePosition(val, ref val2) && !(Vector3.Distance(anchor, val2) < minDistance) && graph.GetNodeFlags(val, ref flags) && IsNodeValidForRogue(flags))
				{
					position = val2;
					flag = true;
					break;
				}
			}
			LastNodeThreshold = minDistance;
			LastNodeFound = flag;
			LastNodePosition = position;
			return flag;
		}

		private bool TryFindAnyValidNode(NodeGraph graph, out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			int nodeCount = graph.GetNodeCount();
			NodeIndex val = default(NodeIndex);
			Vector3 val2 = default(Vector3);
			NodeFlags flags = default(NodeFlags);
			for (int i = 0; i < nodeCount; i++)
			{
				((NodeIndex)(ref val))..ctor(i);
				if (graph.GetNodePosition(val, ref val2) && graph.GetNodeFlags(val, ref flags) && IsNodeValidForRogue(flags))
				{
					position = val2;
					LastNodeThreshold = -1f;
					LastNodeFound = true;
					LastNodePosition = position;
					return true;
				}
			}
			LastNodeThreshold = -1f;
			LastNodeFound = false;
			LastNodePosition = Vector3.zero;
			return false;
		}

		private bool IsNodeValidForRogue(NodeFlags flags)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			if ((Object)(object)RogueSpawnCard.RogueCard == (Object)null)
			{
				return true;
			}
			NodeFlags requiredFlags = ((SpawnCard)RogueSpawnCard.RogueCard).requiredFlags;
			NodeFlags forbiddenFlags = ((SpawnCard)RogueSpawnCard.RogueCard).forbiddenFlags;
			if ((flags & forbiddenFlags) > 0)
			{
				return false;
			}
			if ((int)requiredFlags != 0 && (flags & requiredFlags) == 0)
			{
				return false;
			}
			return true;
		}

		private void PruneRogueList()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			for (int num = rogueMasters.Count - 1; num >= 0; num--)
			{
				CharacterMaster val = rogueMasters[num];
				if (!Object.op_Implicit((Object)(object)val))
				{
					Debug.LogWarning((object)"[Rogue][DEBUG] Prune: NULL master removed.");
					rogueMasters.RemoveAt(num);
				}
				else if (val.teamIndex != RogueTeamPlugin.RogueTeam)
				{
					string[] obj = new string[5]
					{
						"[Rogue][DEBUG] Prune: Master ",
						((Object)val).name,
						" removed due to WRONG TEAM (",
						null,
						null
					};
					TeamIndex teamIndex = val.teamIndex;
					obj[3] = ((object)(TeamIndex)(ref teamIndex)).ToString();
					obj[4] = ")";
					Debug.LogWarning((object)string.Concat(obj));
					rogueMasters.RemoveAt(num);
				}
				else
				{
					CharacterBody body = val.GetBody();
					if (!Object.op_Implicit((Object)(object)body))
					{
						Debug.LogWarning((object)("[Rogue][DEBUG] Prune: Master " + ((Object)val).name + " has NO BODY."));
						rogueMasters.RemoveAt(num);
					}
					else if (!Object.op_Implicit((Object)(object)body.healthComponent) || !body.healthComponent.alive)
					{
						Debug.LogWarning((object)("[Rogue][DEBUG] Prune: Master " + ((Object)val).name + " body is DEAD."));
						rogueMasters.RemoveAt(num);
					}
				}
			}
		}

		private void RefreshLeaderFromSquad()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			orCreateSquad.EnsureLeader();
			CharacterMaster leader = orCreateSquad.Leader;
			if (Object.op_Implicit((Object)(object)leader) && rogueMasters.Contains(leader))
			{
				if ((Object)(object)leaderMaster != (Object)(object)leader)
				{
					leaderMaster = leader;
					Debug.Log((object)("[Rogue][DEBUG] RefreshLeaderFromSquad: New leader=" + ((Object)leaderMaster).name));
				}
				return;
			}
			if ((Object)(object)leaderMaster != (Object)null)
			{
				Debug.Log((object)"[Rogue][DEBUG] RefreshLeaderFromSquad: No valid leader, clearing.");
			}
			leaderMaster = null;
			orCreateSquad.SetLeader(null);
		}

		private int CountAliveRogues()
		{
			int num = 0;
			foreach (CharacterMaster rogueMaster in rogueMasters)
			{
				if (Object.op_Implicit((Object)(object)rogueMaster))
				{
					CharacterBody body = rogueMaster.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						num++;
					}
				}
			}
			return num;
		}

		private Vector3? GetLeaderPosition()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)leaderMaster))
			{
				return null;
			}
			CharacterBody body = leaderMaster.GetBody();
			if (!Object.op_Implicit((Object)(object)body))
			{
				return null;
			}
			return body.corePosition;
		}

		private Vector3? GetAnyRoguePosition()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			foreach (CharacterMaster rogueMaster in rogueMasters)
			{
				if (Object.op_Implicit((Object)(object)rogueMaster))
				{
					CharacterBody body = rogueMaster.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						return body.corePosition;
					}
				}
			}
			return null;
		}

		private Vector3? GetAnyPlayerPosition()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (PlayerCharacterMasterController.instances == null || PlayerCharacterMasterController.instances.Count == 0)
			{
				return null;
			}
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master))
				{
					CharacterBody body = instance.master.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						return body.corePosition;
					}
				}
			}
			return null;
		}
	}
	public static class RogueFormation
	{
		public static Dictionary<CharacterMaster, Vector3> ComputeFormationPositions(RogueFormationType type, Vector3 anchor, Vector3 forward, List<CharacterMaster> members, CharacterMaster leader)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<CharacterMaster, Vector3> dictionary = new Dictionary<CharacterMaster, Vector3>();
			if (members == null || members.Count == 0)
			{
				return dictionary;
			}
			List<Vector3> list = ComputeOffsets(type, members.Count);
			for (int i = 0; i < members.Count; i++)
			{
				CharacterMaster val = members[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					Vector3 val2 = list[i];
					Vector3 val3 = Quaternion.LookRotation(forward) * val2;
					dictionary[val] = anchor + val3;
				}
			}
			return dictionary;
		}

		private static List<Vector3> ComputeOffsets(RogueFormationType type, int count)
		{
			return type switch
			{
				RogueFormationType.Line => ComputeLineOffsets(count), 
				RogueFormationType.Square => ComputeSquareOffsets(count), 
				RogueFormationType.Wedge => ComputeWedgeOffsets(count), 
				RogueFormationType.Circle => ComputeCircleOffsets(count), 
				RogueFormationType.LeaderSquare => ComputeLeaderSquareOffsets(count), 
				_ => ComputeLineOffsets(count), 
			};
		}

		private static List<Vector3> ComputeLineOffsets(int count)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(new Vector3(0f, 0f, 2f));
			float num = 2.5f;
			for (int i = 1; i < count; i++)
			{
				float num2 = (float)(i - 1) * num - (float)(count - 2) * num * 0.5f;
				list.Add(new Vector3(num2, 0f, 0f));
			}
			return list;
		}

		private static List<Vector3> ComputeSquareOffsets(int count)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(new Vector3(0f, 0f, 2f));
			int num = count - 1;
			int num2 = Mathf.CeilToInt(Mathf.Sqrt((float)num));
			float num3 = 2.5f;
			for (int i = 0; i < num; i++)
			{
				int num4 = i / num2;
				int num5 = i % num2;
				float num6 = ((float)num5 - (float)(num2 - 1) * 0.5f) * num3;
				float num7 = (0f - (float)(num4 + 1)) * num3;
				list.Add(new Vector3(num6, 0f, num7));
			}
			return list;
		}

		private static List<Vector3> ComputeWedgeOffsets(int count)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(new Vector3(0f, 0f, 2f));
			float num = 2.5f;
			int num2 = 1;
			int num3 = 1;
			for (int i = 1; i < count; i++)
			{
				if (i % 2 == 1)
				{
					list.Add(new Vector3((0f - (float)num2) * num, 0f, (0f - (float)num2) * num));
					num2++;
				}
				else
				{
					list.Add(new Vector3((float)num3 * num, 0f, (0f - (float)num3) * num));
					num3++;
				}
			}
			return list;
		}

		private static List<Vector3> ComputeCircleOffsets(int count)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(new Vector3(0f, 0f, 3f));
			float num = 4f;
			int num2 = count - 1;
			for (int i = 0; i < num2; i++)
			{
				float num3 = 360f / (float)num2 * (float)i;
				float num4 = num3 * ((float)Math.PI / 180f);
				float num5 = Mathf.Cos(num4) * num;
				float num6 = Mathf.Sin(num4) * num;
				list.Add(new Vector3(num5, 0f, num6));
			}
			return list;
		}

		private static List<Vector3> ComputeLeaderSquareOffsets(int count)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(new Vector3(0f, 0f, 3f));
			int num = count - 1;
			int num2 = Mathf.CeilToInt(Mathf.Sqrt((float)num));
			float num3 = 2.5f;
			for (int i = 0; i < num; i++)
			{
				int num4 = i / num2;
				int num5 = i % num2;
				float num6 = ((float)num5 - (float)(num2 - 1) * 0.5f) * num3;
				float num7 = (0f - (float)(num4 + 1)) * num3;
				list.Add(new Vector3(num6, 0f, num7));
			}
			return list;
		}
	}
	public enum RogueFormationType
	{
		Line,
		Square,
		Wedge,
		Circle,
		LeaderSquare
	}
	public static class RogueHostility
	{
		public static void ApplyCustomHostility(BaseAI ai, TeamIndex rogueTeam)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ai == (Object)null) && !((Object)(object)ai.master == (Object)null))
			{
				ai.master.teamIndex = rogueTeam;
				ai.enemyAttention = ai.enemyAttentionDuration;
				ai.prioritizePlayers = false;
				ai.neverRetaliateFriendlies = false;
			}
		}
	}
	public static class RogueOrders
	{
		public static void IssueLeaderFormationOrder(RogueFormationType type)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)RogueDirector.instance == (Object)null)
			{
				Debug.LogWarning((object)"[RogueOrders] No RogueDirector instance.");
				return;
			}
			if (!RogueDirector.instance.HasLeader)
			{
				Debug.LogWarning((object)"[RogueOrders] No Rogue leader to issue formation order.");
				return;
			}
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			if (orCreateSquad.Members.Count == 0)
			{
				Debug.LogWarning((object)"[RogueOrders] Squad has no members.");
				return;
			}
			CharacterMaster leader = orCreateSquad.Leader;
			if (!Object.op_Implicit((Object)(object)leader))
			{
				Debug.LogWarning((object)"[RogueOrders] Squad leader is null.");
				return;
			}
			CharacterBody body = leader.GetBody();
			if (!Object.op_Implicit((Object)(object)body))
			{
				Debug.LogWarning((object)"[RogueOrders] Leader body is null.");
				return;
			}
			Vector3 corePosition = body.corePosition;
			Vector3 forward = ((Component)body).transform.forward;
			List<CharacterMaster> members = orCreateSquad.Members;
			Dictionary<CharacterMaster, Vector3> dictionary = RogueFormation.ComputeFormationPositions(type, corePosition, forward, members, leader);
			if (dictionary == null || dictionary.Count == 0)
			{
				Debug.LogWarning((object)"[RogueOrders] Formation returned no positions.");
				return;
			}
			CharacterMaster val = FindRoguePlayerMaster();
			Vector3 val2 = Vector3.zero;
			bool flag = false;
			foreach (KeyValuePair<CharacterMaster, Vector3> item in dictionary)
			{
				CharacterMaster key = item.Key;
				Vector3 value = item.Value;
				if (!Object.op_Implicit((Object)(object)key))
				{
					continue;
				}
				if (Object.op_Implicit((Object)(object)val) && (Object)(object)key == (Object)(object)val)
				{
					val2 = value;
					flag = true;
					continue;
				}
				CharacterBody body2 = key.GetBody();
				if (Object.op_Implicit((Object)(object)body2))
				{
					RogueTacticalAI component = ((Component)body2).GetComponent<RogueTacticalAI>();
					if ((Object)(object)component != (Object)null)
					{
						component.SetFormationPosition(value);
					}
				}
			}
			if (flag)
			{
				SpawnFormationPing(val2);
				Debug.Log((object)$"[RogueOrders] Leader issued {type} formation. Player slot at {val2}.");
			}
			else
			{
				Debug.Log((object)$"[RogueOrders] Leader issued {type} formation. No player in squad to ping.");
			}
		}

		public static CharacterMaster FindRoguePlayerMaster()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster result;
			if (PlayerCharacterMasterController.instances == null)
			{
				result = null;
			}
			else
			{
				foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
				{
					if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master))
					{
						CharacterMaster master = instance.master;
						if (master.teamIndex == RogueTeamPlugin.RogueTeam)
						{
							return master;
						}
					}
				}
				result = null;
			}
			return result;
		}

		private static void SpawnFormationPing(Vector3 position)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GameObject val = Resources.Load<GameObject>("Prefabs/Effects/GenericPingEffect");
			if (Object.op_Implicit((Object)(object)val))
			{
				EffectData val2 = new EffectData
				{
					origin = position
				};
				EffectManager.SpawnEffect(val, val2, true);
			}
			Chat.AddMessage("<color=#00FFFF>Move to formation position!</color>");
		}
	}
	public class RoguePersistence : MonoBehaviour
	{
		public static RoguePersistence instance;

		private readonly List<CharacterMaster> survivors = new List<CharacterMaster>();

		public IReadOnlyList<CharacterMaster> SurvivorList => survivors;

		public static void Init()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Invalid comparison between Unknown and I4
			if (RogueArtifact.Enabled)
			{
				if (!Object.op_Implicit((Object)(object)instance))
				{
					GameObject val = new GameObject("RoguePersistence");
					instance = val.AddComponent<RoguePersistence>();
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				SceneDef sceneDefFromSceneName = SceneCatalog.GetSceneDefFromSceneName(((Scene)(ref scene)).name);
				if (Object.op_Implicit((Object)(object)sceneDefFromSceneName) && (int)sceneDefFromSceneName.sceneType == 1)
				{
					instance.RestoreSurvivors();
				}
			}
		}

		public static void CollectBeforeStageEnd()
		{
			if (Object.op_Implicit((Object)(object)instance))
			{
				instance.CollectSurvivors();
			}
		}

		private void CollectSurvivors()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			survivors.Clear();
			RogueDirector.ClearRogues();
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			foreach (CharacterMaster member in orCreateSquad.Members)
			{
				if (Object.op_Implicit((Object)(object)member))
				{
					CharacterBody body = member.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						survivors.Add(member);
					}
				}
			}
			Debug.Log((object)$"[Rogue] Collected {survivors.Count} surviving rogues for persistence.");
		}

		private void RestoreSurvivors()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (survivors.Count == 0)
			{
				Debug.Log((object)"[Rogue] No rogues to restore.");
				return;
			}
			SceneInfo val = SceneInfo.instance;
			if (!Object.op_Implicit((Object)(object)val))
			{
				Debug.LogWarning((object)"[Rogue] SceneInfo missing during restore.");
				return;
			}
			NodeGraph nodeGraph = val.GetNodeGraph((GraphType)0);
			if (!Object.op_Implicit((Object)(object)nodeGraph))
			{
				Debug.LogWarning((object)"[Rogue] Ground node graph missing during restore.");
				return;
			}
			if (!TryGetAlivePlayerPosition(out var position))
			{
				Debug.LogWarning((object)"[Rogue] No player anchor found for restore.");
				return;
			}
			if (!FindFurthestNode(nodeGraph, position, out var position2))
			{
				Debug.LogWarning((object)"[Rogue] Could not find furthest node for restore.");
				return;
			}
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeamPlugin.RogueTeam);
			foreach (CharacterMaster survivor in survivors)
			{
				if (!Object.op_Implicit((Object)(object)survivor))
				{
					continue;
				}
				CharacterBody body = survivor.GetBody();
				if (!Object.op_Implicit((Object)(object)body))
				{
					continue;
				}
				((Component)body).transform.position = position2;
				HealthComponent healthComponent = body.healthComponent;
				if (Object.op_Implicit((Object)(object)healthComponent))
				{
					float num = ((healthComponent.fullHealth > 0f) ? (healthComponent.health / healthComponent.fullHealth) : 1f);
					if (num < 0.4f)
					{
						healthComponent.health = healthComponent.fullHealth * 0.4f;
					}
				}
				RogueDirector.RegisterExistingRogue(survivor);
				orCreateSquad.AddMember(survivor);
			}
			Debug.Log((object)$"[Rogue] Restored {survivors.Count} rogues on new stage.");
			survivors.Clear();
		}

		private bool FindFurthestNode(NodeGraph graph, Vector3 anchor, out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			position = anchor;
			bool flag = false;
			float num = 0f;
			int nodeCount = graph.GetNodeCount();
			NodeIndex val = default(NodeIndex);
			Vector3 val2 = default(Vector3);
			NodeFlags flags = default(NodeFlags);
			for (int i = 0; i < nodeCount; i++)
			{
				((NodeIndex)(ref val))..ctor(i);
				if (graph.GetNodePosition(val, ref val2) && graph.GetNodeFlags(val, ref flags) && IsNodeValidForRogue(flags))
				{
					float num2 = Vector3.Distance(anchor, val2);
					if (!flag || num2 > num)
					{
						num = num2;
						position = val2;
						flag = true;
					}
				}
			}
			return flag;
		}

		private bool IsNodeValidForRogue(NodeFlags flags)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			if ((Object)(object)RogueSpawnCard.RogueCard == (Object)null)
			{
				return true;
			}
			NodeFlags requiredFlags = ((SpawnCard)RogueSpawnCard.RogueCard).requiredFlags;
			NodeFlags forbiddenFlags = ((SpawnCard)RogueSpawnCard.RogueCard).forbiddenFlags;
			if ((flags & forbiddenFlags) > 0)
			{
				return false;
			}
			if ((int)requiredFlags != 0 && (flags & requiredFlags) == 0)
			{
				return false;
			}
			return true;
		}

		private bool TryGetAlivePlayerPosition(out Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			if (PlayerCharacterMasterController.instances == null || PlayerCharacterMasterController.instances.Count == 0)
			{
				return false;
			}
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master))
				{
					CharacterBody body = instance.master.GetBody();
					if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive)
					{
						position = body.corePosition;
						return true;
					}
				}
			}
			return false;
		}
	}
	public static class RogueReputation
	{
		public static bool PlayerAttackedRogues;

		public static bool RoguesAttackedPlayer;

		public static float PeaceTimer;

		public static bool OfferShown;

		public static float OfferTimer;

		public const float OfferDuration = 30f;

		public static bool IsEligible => !PlayerAttackedRogues && !RoguesAttackedPlayer;

		public static void Reset()
		{
			PlayerAttackedRogues = false;
			RoguesAttackedPlayer = false;
			PeaceTimer = 0f;
			OfferShown = false;
			OfferTimer = 0f;
		}

		public static void Update(float deltaTime)
		{
			if (!IsEligible)
			{
				return;
			}
			if (OfferShown)
			{
				OfferTimer += deltaTime;
				if (OfferTimer >= 30f)
				{
					OfferShown = false;
					Chat.AddMessage("<color=#00FFAA>[Rogue]</color> The offer has expired.");
				}
				return;
			}
			PeaceTimer += deltaTime;
			if (PeaceTimer >= 180f && !OfferShown)
			{
				OfferShown = true;
				OfferTimer = 0f;
				Chat.AddMessage("<color=#00FFAA>[Rogue]</color> You have shown restraint. Join the Rogue Faction? Type: <color=#00FFAA>/joinrogue</color>");
			}
		}
	}
	public static class RogueSpawnCard
	{
		public static CharacterSpawnCard RogueCard;

		public static DirectorCardCategorySelection RogueDCCS;

		public static CharacterSpawnCard CaptainCard;

		public static void Init()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			RogueCard = ScriptableObject.CreateInstance<CharacterSpawnCard>();
			((Object)RogueCard).name = "cscRogueUnit";
			((SpawnCard)RogueCard).prefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Commando/CommandoMonsterMaster.prefab").WaitForCompletion();
			((SpawnCard)RogueCard).sendOverNetwork = true;
			((SpawnCard)RogueCard).hullSize = (HullClassification)0;
			((SpawnCard)RogueCard).nodeGraphType = (GraphType)0;
			((SpawnCard)RogueCard).requiredFlags = (NodeFlags)0;
			((SpawnCard)RogueCard).forbiddenFlags = (NodeFlags)4;
			((SpawnCard)RogueCard).directorCreditCost = 20;
			((SpawnCard)RogueCard).occupyPosition = false;
			RogueCard.noElites = true;
			RogueDCCS = ScriptableObject.CreateInstance<DirectorCardCategorySelection>();
			((Object)RogueDCCS).name = "dccsRogueUnits";
			RogueDCCS.AddCategory("RogueUnits", 1f);
			RogueDCCS.AddCard(0, new DirectorCard
			{
				spawnCard = (SpawnCard)(object)RogueCard,
				selectionWeight = 1,
				preventOverhead = false,
				minimumStageCompletions = 0
			});
			CaptainCard = ScriptableObject.CreateInstance<CharacterSpawnCard>();
			((Object)CaptainCard).name = "cscRogueCaptain";
			((SpawnCard)CaptainCard).prefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Captain/CaptainMonsterMaster.prefab").WaitForCompletion();
			((SpawnCard)CaptainCard).sendOverNetwork = true;
			((SpawnCard)CaptainCard).hullSize = (HullClassification)0;
			((SpawnCard)CaptainCard).nodeGraphType = (GraphType)0;
			((SpawnCard)CaptainCard).requiredFlags = (NodeFlags)0;
			((SpawnCard)CaptainCard).forbiddenFlags = (NodeFlags)4;
			((SpawnCard)CaptainCard).directorCreditCost = 0;
			((SpawnCard)CaptainCard).occupyPosition = false;
			CaptainCard.noElites = true;
			Debug.Log((object)"[Rogue] RogueSpawnCard + RogueDCCS + CaptainCard initialized.");
		}
	}
	public class RogueSquad
	{
		private static readonly Dictionary<TeamIndex, RogueSquad> squads = new Dictionary<TeamIndex, RogueSquad>();

		public readonly List<CharacterMaster> Members = new List<CharacterMaster>();

		public HurtBox SharedTarget;

		public TeamIndex Team { get; private set; }

		public CharacterMaster Leader { get; private set; }

		public bool HasLeader
		{
			get
			{
				if ((Object)(object)Leader == (Object)null)
				{
					return false;
				}
				CharacterBody body = Leader.GetBody();
				return (Object)(object)body != (Object)null && (Object)(object)body.healthComponent != (Object)null && body.healthComponent.alive;
			}
		}

		public static RogueSquad GetOrCreateSquad(TeamIndex team)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!squads.TryGetValue(team, out var value))
			{
				value = new RogueSquad(team);
				squads[team] = value;
			}
			return value;
		}

		public static void RemoveFromSquad(CharacterMaster master, TeamIndex team)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (squads.TryGetValue(team, out var value))
			{
				value.RemoveMember(master);
			}
		}

		public void SetLeader(CharacterMaster master)
		{
			Leader = master;
		}

		public RogueSquad(TeamIndex team)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Team = team;
		}

		public void AddMember(CharacterMaster master)
		{
			if (!((Object)(object)master == (Object)null) && !Members.Contains(master))
			{
				Members.Add(master);
			}
		}

		public void RemoveMember(CharacterMaster master)
		{
			if (!((Object)(object)master == (Object)null))
			{
				Members.Remove(master);
				if ((Object)(object)Leader == (Object)(object)master)
				{
					Leader = null;
					EnsureLeader();
				}
			}
		}

		public void EnsureLeader()
		{
			if (HasLeader)
			{
				return;
			}
			Leader = null;
			foreach (CharacterMaster member in Members)
			{
				if (Object.op_Implicit((Object)(object)member))
				{
					CharacterBody body = member.GetBody();
					if ((Object)(object)body != (Object)null && (Object)(object)body.healthComponent != (Object)null && body.healthComponent.alive)
					{
						Leader = member;
						break;
					}
				}
			}
		}

		public Vector3 GetLeaderPosition()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if (HasLeader)
			{
				return Leader.GetBody().corePosition;
			}
			if (Members.Count == 0)
			{
				return Vector3.zero;
			}
			Vector3 val = Vector3.zero;
			int num = 0;
			foreach (CharacterMaster member in Members)
			{
				CharacterBody body = member.GetBody();
				if ((Object)(object)body != (Object)null)
				{
					val += body.corePosition;
					num++;
				}
			}
			return (num > 0) ? (val / (float)num) : Vector3.zero;
		}

		public int GetAliveCount()
		{
			int num = 0;
			foreach (CharacterMaster member in Members)
			{
				CharacterBody body = member.GetBody();
				if ((Object)(object)body != (Object)null && (Object)(object)body.healthComponent != (Object)null && body.healthComponent.alive)
				{
					num++;
				}
			}
			return num;
		}

		public void OrderHoldPosition(Vector3 pos)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (CharacterMaster member in Members)
			{
				if (Object.op_Implicit((Object)(object)member))
				{
					RogueTacticalAI component = ((Component)member).GetComponent<RogueTacticalAI>();
					if ((Object)(object)component != (Object)null)
					{
						component.SetHoldPosition(pos);
					}
				}
			}
		}

		public void OrderFlank(HurtBox target)
		{
			if ((Object)(object)target == (Object)null)
			{
				return;
			}
			SharedTarget = target;
			for (int i = 0; i < Members.Count; i++)
			{
				CharacterMaster val = Members[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					RogueTacticalAI component = ((Component)val).GetComponent<RogueTacticalAI>();
					if (!((Object)(object)component == (Object)null))
					{
						bool leftSide = i % 2 == 0;
						component.SetFlankTarget(target, leftSide);
					}
				}
			}
		}
	}
	public class RogueTacticalAI : MonoBehaviour
	{
		private CharacterMaster master;

		private CharacterBody body;

		private BaseAI baseAI;

		private RogueSquad squad;

		private bool holdingPosition = false;

		private Vector3 holdPosition;

		private bool isFlanking = false;

		private bool flankLeft = false;

		private HurtBox flankTarget;

		private Vector3? formationTarget = null;

		private float formationCheckTimer = 0f;

		private int originalSquadSize = 0;

		private static readonly HashSet<CharacterMaster> roguePlayers = new HashSet<CharacterMaster>();

		public static void RegisterRoguePlayer(CharacterMaster master)
		{
			if ((Object)(object)master != (Object)null)
			{
				roguePlayers.Add(master);
			}
		}

		public void Init(RogueSquad squad)
		{
			this.squad = squad;
			master = ((Component)this).GetComponent<CharacterMaster>();
			if (!Object.op_Implicit((Object)(object)master))
			{
				CharacterBody component = ((Component)this).GetComponent<CharacterBody>();
				master = (Object.op_Implicit((Object)(object)component) ? component.master : null);
			}
			if (Object.op_Implicit((Object)(object)master))
			{
				body = master.GetBody();
				baseAI = ((Component)master).GetComponent<BaseAI>();
				if (!Object.op_Implicit((Object)(object)baseAI))
				{
					baseAI = ((Component)master).gameObject.AddComponent<BaseAI>();
				}
				if (squad != null && squad.Members != null && squad.Members.Count > 0)
				{
					originalSquadSize = Mathf.Max(originalSquadSize, squad.Members.Count);
				}
			}
		}

		private void FixedUpdate()
		{
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: 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)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body == (Object)null || (Object)(object)baseAI == (Object)null)
			{
				return;
			}
			bool flag = squad != null && (Object)(object)squad.Leader == (Object)(object)master;
			bool hasEnemy = false;
			bool surrounded = false;
			bool closeEnemy = false;
			bool midEnemy = false;
			if (squad != null && (Object)(object)squad.Leader != (Object)null)
			{
				CharacterBody val = squad.Leader.GetBody();
				if (Object.op_Implicit((Object)(object)val))
				{
					GetSquadEnemyInfo(val, out hasEnemy, out surrounded, out closeEnemy, out midEnemy);
				}
			}
			if (flag)
			{
				if (!hasEnemy && !holdingPosition && !isFlanking)
				{
					RogueOrders.IssueLeaderFormationOrder(RogueFormationType.LeaderSquare);
					Vector3 val2 = (Object.op_Implicit((Object)(object)body.inputBank) ? body.inputBank.aimDirection : ((Component)body).transform.forward);
					Vector3 targetPosition = body.corePosition + val2 * 8f;
					baseAI.localNavigator.targetPosition = targetPosition;
				}
				formationCheckTimer += Time.fixedDeltaTime;
				if (formationCheckTimer >= 5f)
				{
					formationCheckTimer = 0f;
					TryIssueFormationOrder();
				}
			}
			if (isFlanking && (Object)(object)flankTarget != (Object)null)
			{
				Vector3 position = ((Component)flankTarget).transform.position;
				Vector3 val3 = position - body.corePosition;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = Vector3.Cross(Vector3.up, normalized);
				Vector3 val5 = position + val4 * (flankLeft ? (-12f) : 12f);
				baseAI.localNavigator.targetPosition = val5;
				if (Vector3.Distance(body.corePosition, val5) < 5f)
				{
					isFlanking = false;
				}
				return;
			}
			if (holdingPosition)
			{
				baseAI.localNavigator.targetPosition = holdPosition;
				body.isSprinting = false;
				return;
			}
			if (formationTarget.HasValue)
			{
				float num = Vector3.Distance(body.corePosition, formationTarget.Value);
				if (num > 3f)
				{
					baseAI.localNavigator.targetPosition = formationTarget.Value;
					return;
				}
			}
			if (squad == null || !((Object)(object)squad.Leader != (Object)null) || !((Object)(object)squad.Leader != (Object)(object)master))
			{
				return;
			}
			CharacterBody val6 = squad.Leader.GetBody();
			if (Object.op_Implicit((Object)(object)val6))
			{
				if (!hasEnemy && formationTarget.HasValue)
				{
					baseAI.localNavigator.targetPosition = formationTarget.Value;
				}
				else
				{
					baseAI.localNavigator.targetPosition = val6.corePosition;
				}
			}
		}

		public void SetFormationPosition(Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			formationTarget = pos;
			holdingPosition = false;
			isFlanking = false;
		}

		public void SetHoldPosition(Vector3 pos)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			holdingPosition = true;
			holdPosition = pos;
			formationTarget = null;
			isFlanking = false;
		}

		public void ClearHoldPosition()
		{
			holdingPosition = false;
		}

		public void SetFlankTarget(HurtBox target, bool leftSide)
		{
			flankTarget = target;
			flankLeft = leftSide;
			isFlanking = true;
			holdingPosition = false;
			formationTarget = null;
		}

		private void TryIssueFormationOrder()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			if (squad == null || squad.Members.Count <= 1)
			{
				return;
			}
			CharacterBody val = body;
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			if (originalSquadSize <= 0)
			{
				originalSquadSize = squad.Members.Count;
			}
			int count = squad.Members.Count;
			int num = Mathf.Max(1, Mathf.CeilToInt((float)originalSquadSize * 0.5f));
			bool flag = count < num;
			Vector3 corePosition = val.corePosition;
			float num2 = 0f;
			foreach (CharacterMaster member in squad.Members)
			{
				if (!Object.op_Implicit((Object)(object)member))
				{
					continue;
				}
				CharacterBody val2 = member.GetBody();
				if (Object.op_Implicit((Object)(object)val2))
				{
					float num3 = Vector3.Distance(corePosition, val2.corePosition);
					if (num3 > num2)
					{
						num2 = num3;
					}
				}
			}
			bool flag2 = false;
			CharacterMaster val3 = RogueOrders.FindRoguePlayerMaster();
			if (Object.op_Implicit((Object)(object)val3))
			{
				CharacterBody val4 = val3.GetBody();
				if (Object.op_Implicit((Object)(object)val4))
				{
					float num4 = Vector3.Distance(corePosition, val4.corePosition);
					if (num4 > 30f)
					{
						flag2 = true;
					}
				}
			}
			GetSquadEnemyInfo(val, out var hasEnemy, out var surrounded, out var closeEnemy, out var midEnemy);
			if (Object.op_Implicit((Object)(object)val.healthComponent) && val.healthComponent.health / val.healthComponent.fullHealth < 0.35f)
			{
				flag = true;
			}
			if (flag)
			{
				if (!hasEnemy)
				{
					if (num2 > 20f || flag2)
					{
						RogueOrders.IssueLeaderFormationOrder(RogueFormationType.LeaderSquare);
					}
				}
				else
				{
					RogueOrders.IssueLeaderFormationOrder(RogueFormationType.Circle);
				}
			}
			else if (!hasEnemy)
			{
				if (num2 > 25f || flag2)
				{
					RogueOrders.IssueLeaderFormationOrder(RogueFormationType.LeaderSquare);
				}
			}
			else if (surrounded)
			{
				RogueOrders.IssueLeaderFormationOrder(RogueFormationType.Circle);
			}
			else if (closeEnemy)
			{
				RogueOrders.IssueLeaderFormationOrder(RogueFormationType.Wedge);
			}
			else if (midEnemy)
			{
				RogueOrders.IssueLeaderFormationOrder(RogueFormationType.Line);
			}
		}

		private void GetSquadEnemyInfo(CharacterBody leaderBody, out bool hasEnemy, out bool surrounded, out bool closeEnemy, out bool midEnemy)
		{
			//IL_009a: 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)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			hasEnemy = false;
			surrounded = false;
			closeEnemy = false;
			midEnemy = false;
			if (squad == null || squad.Members == null || squad.Members.Count == 0)
			{
				return;
			}
			List<Vector3> list = new List<Vector3>();
			foreach (CharacterMaster member in squad.Members)
			{
				if (!Object.op_Implicit((Object)(object)member))
				{
					continue;
				}
				CharacterBody val = member.GetBody();
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				BullseyeSearch val2 = new BullseyeSearch
				{
					teamMaskFilter = TeamMask.GetUnprotectedTeams(RogueTeamPlugin.RogueTeam),
					maxDistanceFilter = 60f,
					searchOrigin = val.corePosition,
					searchDirection = (Object.op_Implicit((Object)(object)val.inputBank) ? val.inputBank.aimDirection : ((Component)val).transform.forward),
					filterByLoS = true,
					sortMode = (SortMode)1
				};
				val2.RefreshCandidates();
				foreach (HurtBox result in val2.GetResults())
				{
					if (!Object.op_Implicit((Object)(object)result) || (Object)(object)result.healthComponent == (Object)null || (Object)(object)result.healthComponent.body == (Object)null)
					{
						continue;
					}
					CharacterBody val3 = result.healthComponent.body;
					hasEnemy = true;
					float num = Vector3.Distance(val.corePosition, val3.corePosition);
					if (num <= 25f)
					{
						closeEnemy = true;
					}
					else if (num <= 40f)
					{
						midEnemy = true;
					}
					if (Object.op_Implicit((Object)(object)leaderBody))
					{
						Vector3 val4 = val3.corePosition - leaderBody.corePosition;
						Vector3 normalized = ((Vector3)(ref val4)).normalized;
						list.Add(normalized);
					}
					break;
				}
			}
			if (list.Count < 2)
			{
				return;
			}
			float num2 = 0f;
			for (int i = 0; i < list.Count; i++)
			{
				for (int j = i + 1; j < list.Count; j++)
				{
					float num3 = Vector3.Angle(list[i], list[j]);
					if (num3 > num2)
					{
						num2 = num3;
					}
				}
			}
			if (num2 >= 120f)
			{
				surrounded = true;
			}
		}
	}
	public static class RogueTeamDef
	{
		public static TeamIndex CreateTeam()
		{
			//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_0012: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			TeamDef val = new TeamDef
			{
				nameToken = "ROGUE_TEAM"
			};
			TeamBehavior val2 = new TeamBehavior("ROGUE_TEAM", (TeamClassification)4);
			TeamIndex result = TeamsAPI.RegisterTeam(val, val2);
			Debug.Log((object)("[Rogue] Registered custom team via TeamsAPI: " + ((object)(TeamIndex)(ref result)).ToString()));
			return result;
		}
	}
	[BepInPlugin("com.dad.rogueteam", "Rogue Team Tactical AI", "1.0.0")]
	public class RogueTeamPlugin : BaseUnityPlugin
	{
		public static TeamIndex RogueTeam;

		private void Awake()
		{
			//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)
			RogueTeam = RogueTeamDef.CreateTeam();
			LanguageAPI.Add("NEW_FRIENDS_ACHIEVEMENT_NAME", "New Friends");
			LanguageAPI.Add("NEW_FRIENDS_ACHIEVEMENT_DESC", "You brought some friends along, yeah? Kept you waiting, huh.");
			LanguageAPI.Add("NEW_FRIENDS_UNLOCKABLE_NAME", "New Friends");
			RogueArtifact.Init();
			RogueSpawnCard.Init();
			RogueDirector.Init();
			CharacterBody.onBodyStartGlobal += OnBodyStart;
			GlobalEventManager.onCharacterDeathGlobal += OnCharacterDeath;
			GlobalEventManager.onServerDamageDealt += OnDamageDealt;
			TeleporterInteraction.onTeleporterChargedGlobal += OnTeleporterCharged;
			Run.onRunStartGlobal += delegate
			{
				RogueReputation.Reset();
			};
			Stage.onServerStageBegin += OnStageBegin;
			Run.onClientGameOverGlobal += OnGameOver;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[Rogue] Plugin initialized.");
		}

		private void OnBodyStart(CharacterBody body)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!RogueArtifact.Enabled || !Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.master) || !Object.op_Implicit((Object)(object)body.teamComponent) || body.teamComponent.teamIndex != RogueTeam)
			{
				return;
			}
			RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeam);
			if (body.isPlayerControlled)
			{
				RogueTacticalAI.RegisterRoguePlayer(body.master);
				return;
			}
			orCreateSquad.AddMember(body.master);
			if (!orCreateSquad.HasLeader)
			{
				orCreateSquad.SetLeader(body.master);
				if (body.bodyIndex != BodyCatalog.FindBodyIndex("CaptainBody"))
				{
					TransformLeaderIntoCaptain(body.master);
					return;
				}
			}
			BaseAI val = ((Component)body.master).GetComponent<BaseAI>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = ((Component)body.master).gameObject.AddComponent<BaseAI>();
			}
			RogueHostility.ApplyCustomHostility(val, RogueTeam);
			RogueTacticalAI rogueTacticalAI = ((Component)body.master).GetComponent<RogueTacticalAI>();
			if (!Object.op_Implicit((Object)(object)rogueTacticalAI))
			{
				rogueTacticalAI = ((Component)body.master).gameObject.AddComponent<RogueTacticalAI>();
			}
			rogueTacticalAI.Init(orCreateSquad);
		}

		private void OnCharacterDeath(DamageReport report)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (RogueArtifact.Enabled)
			{
				CharacterMaster val = (Object.op_Implicit((Object)(object)report?.victimBody) ? report.victimBody.master : null);
				if ((Object)(object)val != (Object)null)
				{
					RogueSquad.RemoveFromSquad(val, report.victimBody.teamComponent.teamIndex);
				}
			}
		}

		private void OnDamageDealt(DamageReport report)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (report == null)
			{
				return;
			}
			CharacterBody attackerBody = report.attackerBody;
			CharacterBody victimBody = report.victimBody;
			if (Object.op_Implicit((Object)(object)attackerBody) && Object.op_Implicit((Object)(object)victimBody))
			{
				if (attackerBody.isPlayerControlled && victimBody.teamComponent.teamIndex == RogueTeam)
				{
					RogueReputation.PlayerAttackedRogues = true;
				}
				if (victimBody.isPlayerControlled && attackerBody.teamComponent.teamIndex == RogueTeam)
				{
					RogueReputation.RoguesAttackedPlayer = true;
				}
			}
		}

		private void OnTeleporterCharged(TeleporterInteraction tp)
		{
			if (RogueArtifact.Enabled && RogueReputation.IsEligible)
			{
				RogueReputation.PlayerAttackedRogues = true;
				Chat.AddMessage("<color=#00FFAA>[Rogue]</color> You have shown restraint. Join the Rogue Faction? Type: <color=#00FFAA>/joinrogue</color>");
			}
		}

		private void OnStageBegin(Stage stage)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!RogueArtifact.Enabled)
			{
				return;
			}
			SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
			if (!Object.op_Implicit((Object)(object)sceneDefForCurrentScene) || sceneDefForCurrentScene.cachedName != "moon2")
			{
				return;
			}
			CharacterBody val = null;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterBody body = instance.master.GetBody();
				if (Object.op_Implicit((Object)(object)body) && body.teamComponent.teamIndex == RogueTeam)
				{
					val = body;
					break;
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				GameObject val2 = GameObject.Find("EscapeSequenceController");
				if (Object.op_Implicit((Object)(object)val2))
				{
					RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeam);
					orCreateSquad.OrderHoldPosition(val2.transform.position);
					Chat.AddMessage("<color=#00FFAA>[Rogue]</color> Your squad is holding the ship perimeter.");
				}
			}
		}

		private void OnGameOver(Run run, RunReport report)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (!RogueArtifact.Enabled || (Object)(object)report?.gameEnding == (Object)null || !report.gameEnding.isWin)
			{
				return;
			}
			bool flag = false;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterBody body = instance.master.GetBody();
				if (Object.op_Implicit((Object)(object)body) && body.teamComponent.teamIndex == RogueTeam)
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				Chat.AddMessage("<color=#00FFAA>[Rogue Epilogue]</color> ...And so they left. The survivors escaped the planet once more — with a few new 'Rogue' friends at their side.");
			}
		}

		private void TransformLeaderIntoCaptain(CharacterMaster oldMaster)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			CharacterBody oldBody = (Object.op_Implicit((Object)(object)oldMaster) ? oldMaster.GetBody() : null);
			if (!Object.op_Implicit((Object)(object)oldBody))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"[Rogue] Cannot promote leader — no body found.");
				return;
			}
			Vector3 corePosition = oldBody.corePosition;
			Quaternion rotation = ((Component)oldBody).transform.rotation;
			Inventory oldInv = oldMaster.inventory;
			DirectorPlacementRule val = new DirectorPlacementRule
			{
				placementMode = (PlacementMode)0,
				position = corePosition
			};
			DirectorSpawnRequest val2 = new DirectorSpawnRequest((SpawnCard)(object)RogueSpawnCard.CaptainCard, val, RoR2Application.rng);
			val2.onSpawnedServer = (Action<SpawnResult>)Delegate.Combine(val2.onSpawnedServer, (Action<SpawnResult>)delegate(SpawnResult result)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				if (!result.success || !Object.op_Implicit((Object)(object)result.spawnedInstance))
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"[Rogue] Captain spawn failed.");
				}
				else
				{
					CharacterMaster component = result.spawnedInstance.GetComponent<CharacterMaster>();
					if (!Object.op_Implicit((Object)(object)component))
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"[Rogue] Spawned Captain missing CharacterMaster.");
					}
					else
					{
						component.teamIndex = RogueTeam;
						if (Object.op_Implicit((Object)(object)oldInv) && Object.op_Implicit((Object)(object)component.inventory))
						{
							component.inventory.CopyItemsFrom(oldInv);
						}
						CharacterBody body = component.GetBody();
						if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.teamComponent))
						{
							body.teamComponent.teamIndex = RogueTeam;
						}
						RogueDirector.RegisterExistingRogue(component);
						RogueSquad orCreateSquad = RogueSquad.GetOrCreateSquad(RogueTeam);
						orCreateSquad.AddMember(component);
						orCreateSquad.SetLeader(component);
						if (Object.op_Implicit((Object)(object)body) && !Object.op_Implicit((Object)(object)((Component)body).GetComponent<RogueTacticalAI>()))
						{
							((Component)body).gameObject.AddComponent<RogueTacticalAI>().Init(orCreateSquad);
						}
						if (Object.op_Implicit((Object)(object)oldBody))
						{
							Object.Destroy((Object)(object)((Component)oldBody).gameObject);
						}
						if (Object.op_Implicit((Object)(object)oldMaster))
						{
							Object.Destroy((Object)(object)((Component)oldMaster).gameObject);
						}
						((BaseUnityPlugin)this).Logger.LogInfo((object)"[Rogue] Leader promoted to Captain via DirectorSpawnRequest.");
					}
				}
			});
			if (!Object.op_Implicit((Object)(object)DirectorCore.instance))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"[Rogue] DirectorCore missing — cannot spawn Captain.");
			}
			else
			{
				DirectorCore.instance.TrySpawnObject(val2);
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCJoinRogue(ConCommandArgs args)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody senderBody = ((ConCommandArgs)(ref args)).senderBody;
			if (Object.op_Implicit((Object)(object)senderBody))
			{
				senderBody.teamComponent.teamIndex = RogueTeam;
				if (Object.op_Implicit((Object)(object)senderBody.master))
				{
					RogueTacticalAI.RegisterRoguePlayer(senderBody.master);
				}
				Chat.AddMessage("<color=#00FFAA>[Rogue]</color> You are now part of the Rogue Faction.");
			}
		}
	}
}
namespace RogueTeamPlugin.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("RogueTeamPlugin.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal Resources()
		{
		}
	}
	[CompilerGenerated]
	[GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.11.0.0")]
	internal sealed class Settings : ApplicationSettingsBase
	{
		private static Settings defaultInstance = (Settings)(object)SettingsBase.Synchronized((SettingsBase)(object)new Settings());

		public static Settings Default => defaultInstance;
	}
}