Decompiled source of Attrition v1.1.0

Attrition.dll

Decompiled 21 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using TFBGames;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Attrition")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace Attrition;

[DefaultExecutionOrder(-10000)]
public sealed class AttritionInputShieldDriver : MonoBehaviour
{
	internal Action Tick;

	private void Update()
	{
		if (Tick != null)
		{
			Tick();
		}
	}
}
public sealed class AttritionInputShieldTarget : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollHandler
{
	public void OnPointerDown(PointerEventData e)
	{
	}

	public void OnPointerUp(PointerEventData e)
	{
	}

	public void OnPointerClick(PointerEventData e)
	{
	}

	public void OnBeginDrag(PointerEventData e)
	{
	}

	public void OnDrag(PointerEventData e)
	{
	}

	public void OnEndDrag(PointerEventData e)
	{
	}

	public void OnScroll(PointerEventData e)
	{
	}
}
[BepInPlugin("attrition.tabs.mod", "Attrition", "1.1.0")]
public sealed class Plugin : BaseUnityPlugin
{
	private enum SlotState
	{
		Active,
		Queued,
		Activating,
		Retired
	}

	private sealed class Slot
	{
		public UnitBlueprint Blueprint;

		public Unit Current;

		public Team Team;

		public Vector3 Position;

		public Quaternion Rotation;

		public int Number;

		public int Cost;

		public int Reserved;

		public float Delay;

		public float Due;

		public SlotState State;

		public bool FlagHeld;
	}

	private sealed class Side
	{
		public int Starting;

		public int Tickets;

		public int Losses;

		public int Replacements;

		public int Failed;

		public Side(int tickets)
		{
			Starting = (Tickets = tickets);
		}
	}

	private sealed class Placement
	{
		public UnitBlueprint Blueprint;

		public Team Team;

		public Vector3 Position;

		public Quaternion Rotation;
	}

	private sealed class CostPick
	{
		public Unit Bound;

		public Placement Original;

		public int Cost;
	}

	private sealed class ObjectiveFlag
	{
		public Vector3 Position;

		public int Owner;

		public int Claim;

		public int InitialOwner;

		public float Progress;

		public bool Contested;

		public float CombatUntil;

		public GameObject Marker;

		public Renderer Cloth;

		public LineRenderer Ring;
	}

	private sealed class FlagQuota
	{
		public int Numerator = 1;

		public int Denominator = 1;

		public int Credit;

		public int Percent => Mathf.RoundToInt(100f * (float)Numerator / (float)Denominator);

		public bool Admit()
		{
			Credit += Numerator;
			if (Credit < Denominator)
			{
				return false;
			}
			Credit -= Denominator;
			return true;
		}

		public void Reset()
		{
			Numerator = (Denominator = 1);
			Credit = 0;
		}
	}

	private readonly List<CostPick> customCosts = new List<CostPick>();

	private readonly Dictionary<Unit, CostPick> boundCosts = new Dictionary<Unit, CostPick>();

	private Dictionary<Unit, Placement> placementCache = new Dictionary<Unit, Placement>();

	private readonly HashSet<Unit> selected = new HashSet<Unit>();

	private int editCost = 1;

	private int menuTab;

	private bool placementGuardReady;

	private bool altMouseCaptured;

	private bool dragSelecting;

	private int gestureFrame = -1;

	private int gestureReleaseFrame = -1;

	private Vector2 dragStart;

	private Vector2 dragEnd;

	private const float DragThreshold = 8f;

	private Texture2D selectionFill;

	private Texture2D selectionBorder;

	private GameObject shieldRoot;

	private GameObject shieldTarget;

	private RectTransform shieldRect;

	private int capturedButtons;

	private int shieldReleaseFrame = -1;

	private Rect lastShieldRect;

	private bool shieldErrorReported;

	private bool showBattleDetails;

	private bool confirmCostReset;

	private string redTicketDraft;

	private string blueTicketDraft;

	private GUIStyle menuHeading;

	private GUIStyle menuHelp;

	private GUIStyle menuTitle;

	private GUIStyle menuLabel;

	private GUIStyle menuButton;

	private GUIStyle activeButton;

	private GUIStyle menuPanel;

	private GUIStyle neutralCard;

	private GUIStyle redCard;

	private GUIStyle blueCard;

	private GUIStyle redLabel;

	private GUIStyle blueLabel;

	private GUIStyle redNumber;

	private GUIStyle blueNumber;

	private GUIStyle menuField;

	private GUIStyle menuToggle;

	private GUIStyle statValue;

	private readonly List<Texture2D> uiTextures = new List<Texture2D>();

	private Texture2D redTrack;

	private Texture2D blueTrack;

	private Texture2D redFill;

	private Texture2D blueFill;

	private static readonly Color RedInk = new Color(1f, 0.53f, 0.53f);

	private static readonly Color BlueInk = new Color(0.51f, 0.71f, 1f);

	private float nextPlacementRefresh;

	private string costStatus = "Alt + click or drag to select units.";

	private readonly List<Slot> slots = new List<Slot>();

	private Side red;

	private Side blue;

	private ConfigEntry<bool> enabledMode;

	private ConfigEntry<bool> waveMode;

	private ConfigEntry<bool> separateTickets;

	private ConfigEntry<int> redTickets;

	private ConfigEntry<int> blueTickets;

	private ConfigEntry<int> maxSpawns;

	private ConfigEntry<float> respawnDelay;

	private ConfigEntry<float> waveInterval;

	private Harmony harmony;

	private MethodInfo decide;

	private bool ready;

	private bool armed;

	private bool initializing;

	private bool running;

	private bool finished;

	private bool nativeFinish;

	private bool panel = true;

	private int previousPhase = -1;

	private int sceneHandle = -1;

	private int attempts;

	private float initDeadline;

	private float nextInit;

	private float nextTick;

	private float startTime;

	private float finalElapsed;

	private float nextReport;

	private float roundWave;

	private bool roundWaves;

	private bool cycleEnabled;

	private bool spawnBlocked;

	private ConfigEntry<bool> suddenDeath;

	private ConfigEntry<float> cooldown;

	private ConfigEntry<float> duration;

	private float roundCooldown;

	private float roundDuration;

	private float nextPhase;

	private string status = "Enable Attrition in placement to start.";

	private static Plugin instance;

	private static readonly int PlacementPhase = 0;

	private static readonly int BattlePhase = 1;

	private const float MenuWidth = 420f;

	private const float PreferredMenuScale = 1.12f;

	private readonly List<ObjectiveFlag> flags = new List<ObjectiveFlag>();

	private Material flagMaterial;

	private ConfigEntry<bool> flagEnabled;

	private ConfigEntry<bool> flagSuppression;

	private ConfigEntry<bool> flagDrain;

	private ConfigEntry<float> flagRadius;

	private ConfigEntry<float> flagCapture;

	private ConfigEntry<float> flagDrainInterval;

	private ConfigEntry<int> flagMinimum;

	private ConfigEntry<int> flagRunnerPercent;

	private bool roundFlags;

	private bool roundSuppression;

	private bool roundDrain;

	private float roundFlagRadius;

	private float roundFlagCapture;

	private float roundDrainInterval;

	private float lastFlagTick;

	private float nextFlagDrain;

	private float nextFlagReport;

	private int roundMin;

	private int roundRunnerPercent;

	private int redOwned;

	private int blueOwned;

	private int initialFlagOwner;

	private readonly FlagQuota redQuota = new FlagQuota();

	private readonly FlagQuota blueQuota = new FlagQuota();

	private string flagMessage = "Aim at ground and press Alt+G.";

	private static readonly Color FlagRed = new Color(0.86f, 0.24f, 0.24f);

	private static readonly Color FlagBlue = new Color(0.25f, 0.51f, 0.95f);

	private static readonly Color FlagNeutral = new Color(0.78f, 0.78f, 0.78f);

	private static readonly Color FlagContest = new Color(0.94f, 0.76f, 0.2f);

	internal static bool FlagRoundActive
	{
		get
		{
			Plugin plugin = instance;
			if ((Object)(object)plugin != (Object)null && plugin.ready && plugin.running && plugin.armed && !plugin.finished)
			{
				return plugin.roundFlags;
			}
			return false;
		}
	}

	internal static float FlagRunnerFraction
	{
		get
		{
			if (!((Object)(object)instance == (Object)null))
			{
				return (float)instance.roundRunnerPercent / 100f;
			}
			return 0f;
		}
	}

	private static BaseGameMode Mode()
	{
		GameModeService service = ServiceLocator.GetService<GameModeService>();
		if (!((Object)(object)service == (Object)null))
		{
			return service.CurrentGameMode;
		}
		return null;
	}

	private static int Phase()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected I4, but got Unknown
		GameStateManager service = ServiceLocator.GetService<GameStateManager>();
		if (service != null)
		{
			return (int)service.GameState;
		}
		return -1;
	}

	private static bool Alive(Unit u)
	{
		if ((Object)(object)u != (Object)null && ((Component)u).gameObject.activeInHierarchy && (Object)(object)u.data != (Object)null)
		{
			return !u.data.Dead;
		}
		return false;
	}

	private static float Clamp(float x, float lo, float hi, float fallback)
	{
		if (!float.IsNaN(x) && !float.IsInfinity(x))
		{
			return Mathf.Clamp(x, lo, hi);
		}
		return fallback;
	}

	private Side Account(Team team)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		if ((int)team != 0)
		{
			return blue;
		}
		return red;
	}

	private void Awake()
	{
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Expected O, but got Unknown
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Expected O, but got Unknown
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Expected O, but got Unknown
		instance = this;
		enabledMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "Enabled", false, "Opt in to Attrition for sandbox battles.");
		separateTickets = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "SeparateTeamTickets", false, "Use independent blue starting tickets.");
		redTickets = ((BaseUnityPlugin)this).Config.Bind<int>("Rules", "RedTickets", 250, "Starting replacement budget; also used for blue unless separate budgets are enabled.");
		blueTickets = ((BaseUnityPlugin)this).Config.Bind<int>("Rules", "BlueTickets", 250, "Blue starting budget when separate budgets are enabled.");
		respawnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Respawn", "InfantrySeconds", 10f, "Respawn delay for all units, in game seconds.");
		waveMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Respawn", "WaveMode", false, "Align individual eligible respawns to the next wave boundary.");
		waveInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Respawn", "WaveSeconds", 15f, "Interval between waves in game seconds.");
		suddenDeath = ((BaseUnityPlugin)this).Config.Bind<bool>("SuddenDeath", "Enabled", false, "Periodically suspend both teams' Attrition replacements.");
		cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("SuddenDeath", "CooldownSeconds", 120f, "Normal spawn time before the first and each following sudden death.");
		duration = ((BaseUnityPlugin)this).Config.Bind<float>("SuddenDeath", "DurationSeconds", 30f, "How long Attrition spawns are blocked each cycle.");
		maxSpawns = ((BaseUnityPlugin)this).Config.Bind<int>("Performance", "MaxSpawnsPerTick", 4, "Maximum replacements per 0.2 game seconds.");
		BindFlags();
		SyncTicketDrafts();
		try
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(GameStateManager), "set_GameState", new Type[1] { typeof(GameState) }, (Type[])null);
			decide = AccessTools.Method(typeof(BaseGameMode), "DecideWinner", new Type[2]
			{
				typeof(Team),
				typeof(string)
			}, (Type[])null);
			if (methodInfo == null || decide == null || methodInfo.ReturnType != typeof(void) || decide.ReturnType != typeof(void))
			{
				throw new InvalidOperationException("Native game-state or winner hook unavailable");
			}
			harmony = new Harmony("attrition.tabs.mod");
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "BeforeStateChange", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)decide, new HarmonyMethod(typeof(Plugin), "BeforeWinner", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			ready = true;
			InstallPlacementGuard();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[Attrition] v1.1.0 ready. Alt+J toggles panel; Alt+click or drag selects placed units for custom 1-25 ticket costs.");
		}
		catch (Exception ex)
		{
			ready = false;
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
		if (!ready)
		{
			return;
		}
		try
		{
			CreateInputShield();
		}
		catch (Exception ex2)
		{
			if ((Object)(object)shieldRoot != (Object)null)
			{
				shieldRoot.SetActive(false);
				Object.Destroy((Object)(object)shieldRoot);
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] Could not create UI input shield: " + ex2.Message));
		}
	}

	private static bool AltHeld()
	{
		if (!Input.GetKey((KeyCode)308))
		{
			return Input.GetKey((KeyCode)307);
		}
		return true;
	}

	private bool SelectionModeActive()
	{
		if (ready && enabledMode != null && enabledMode.Value && Phase() == PlacementPhase)
		{
			return Mode() is SandboxGameMode;
		}
		return false;
	}

	private void InstallPlacementGuard()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Expected O, but got Unknown
		try
		{
			Type? type = typeof(UnitBlueprint).Assembly.GetType("Landfall.TABS.UnitPlacement.UnitPlacementBrush", throwOnError: false);
			if (type == null)
			{
				throw new MissingMemberException("UnitPlacementBrush");
			}
			MethodInfo[] array = (from m in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
				where m.Name == "PlaceUnitInternal" && !m.IsAbstract && !m.ContainsGenericParameters && m.GetParameters().Any((ParameterInfo p) => p.Name == "addToLayout" && p.ParameterType == typeof(bool))
				select m).ToArray();
			if (array.Length == 0)
			{
				throw new MissingMethodException("UnitPlacementBrush.PlaceUnitInternal(addToLayout)");
			}
			MethodInfo[] array2 = array;
			foreach (MethodInfo methodInfo in array2)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "BeforePlaceUnit", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			placementGuardReady = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] Alt placement guard installed (" + array.Length + " placement method(s))."));
		}
		catch (Exception ex)
		{
			placementGuardReady = false;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] Alt selection disabled: placement guard could not be installed. " + ex.Message));
		}
	}

	private void TrackAltMouse()
	{
		if (gestureFrame == Time.frameCount)
		{
			return;
		}
		gestureFrame = Time.frameCount;
		if (!SelectionModeActive() || !placementGuardReady)
		{
			altMouseCaptured = false;
			gestureReleaseFrame = -1;
			return;
		}
		if (AltHeld() && (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0)))
		{
			altMouseCaptured = true;
		}
		if (altMouseCaptured && (Input.GetMouseButtonUp(0) || !Input.GetMouseButton(0)))
		{
			altMouseCaptured = false;
			gestureReleaseFrame = Time.frameCount;
		}
	}

	private static bool BeforePlaceUnit(bool addToLayout)
	{
		Plugin plugin = instance;
		if ((Object)(object)plugin == (Object)null || !plugin.placementGuardReady || !addToLayout)
		{
			return true;
		}
		try
		{
			if (!plugin.SelectionModeActive())
			{
				return true;
			}
			plugin.TrackAltMouse();
			if (AltHeld() && Input.GetMouseButton(0))
			{
				plugin.altMouseCaptured = true;
			}
			bool flag = Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0);
			return !plugin.altMouseCaptured && plugin.gestureReleaseFrame != Time.frameCount && !(AltHeld() && flag);
		}
		catch
		{
			return true;
		}
	}

	private bool MenuVisible(int phase)
	{
		if (ready && panel && Mode() is SandboxGameMode)
		{
			if (phase != PlacementPhase)
			{
				if (armed || initializing || finished)
				{
					if (!enabledMode.Value)
					{
						return red != null;
					}
					return true;
				}
				return false;
			}
			return true;
		}
		return false;
	}

	private void CreateInputShield()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_00f2: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		shieldRoot = new GameObject("Attrition UI Input Shield", new Type[1] { typeof(RectTransform) });
		shieldRoot.SetActive(false);
		shieldRoot.transform.SetParent(((Component)this).transform, false);
		Canvas obj = shieldRoot.AddComponent<Canvas>();
		obj.renderMode = (RenderMode)0;
		obj.overrideSorting = true;
		obj.sortingOrder = 32767;
		obj.scaleFactor = 1f;
		shieldRoot.AddComponent<GraphicRaycaster>();
		shieldTarget = new GameObject("Menu pointer target", new Type[1] { typeof(RectTransform) });
		shieldTarget.transform.SetParent(shieldRoot.transform, false);
		shieldRect = (RectTransform)shieldTarget.transform;
		RectTransform obj2 = shieldRect;
		RectTransform obj3 = shieldRect;
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0f, 1f);
		obj3.anchorMax = val;
		obj2.anchorMin = val;
		shieldRect.pivot = new Vector2(0f, 1f);
		Image obj4 = shieldTarget.AddComponent<Image>();
		((Graphic)obj4).color = Color.clear;
		((Graphic)obj4).raycastTarget = true;
		shieldTarget.AddComponent<AttritionInputShieldTarget>();
		shieldTarget.SetActive(false);
		shieldRoot.AddComponent<AttritionInputShieldDriver>().Tick = RefreshInputShield;
		shieldRoot.SetActive(true);
	}

	private bool ShieldHasCapture()
	{
		if (capturedButtons == 0)
		{
			return Time.frameCount <= shieldReleaseFrame;
		}
		return true;
	}

	private void RefreshInputShield()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: 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_0040: 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_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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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)
		if ((Object)(object)shieldTarget == (Object)null)
		{
			return;
		}
		try
		{
			TrackAltMouse();
			bool flag = MenuVisible(Phase());
			Rect val = PanelRect();
			Vector3 mousePosition = Input.mousePosition;
			bool flag2 = flag && ((Rect)(ref val)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
			for (int i = 0; i < 3; i++)
			{
				int num = 1 << i;
				if (flag2 && Input.GetMouseButtonDown(i))
				{
					capturedButtons |= num;
				}
				if ((capturedButtons & num) != 0 && (Input.GetMouseButtonUp(i) || (!Input.GetMouseButton(i) && !Input.GetMouseButtonDown(i))))
				{
					capturedButtons &= ~num;
					shieldReleaseFrame = Time.frameCount + 1;
				}
			}
			bool flag3 = ShieldHasCapture();
			if (!(flag || flag3))
			{
				if (shieldTarget.activeSelf)
				{
					shieldTarget.SetActive(false);
				}
				return;
			}
			if (flag3)
			{
				((Rect)(ref val))..ctor(0f, 0f, (float)Screen.width, (float)Screen.height);
			}
			if (!shieldTarget.activeSelf || lastShieldRect != val)
			{
				shieldRect.anchoredPosition = new Vector2(((Rect)(ref val)).x, 0f - ((Rect)(ref val)).y);
				shieldRect.sizeDelta = new Vector2(((Rect)(ref val)).width, ((Rect)(ref val)).height);
				lastShieldRect = val;
				shieldTarget.SetActive(true);
				Canvas.ForceUpdateCanvases();
			}
		}
		catch (Exception ex)
		{
			if ((Object)(object)shieldTarget != (Object)null)
			{
				shieldTarget.SetActive(false);
			}
			if (!shieldErrorReported)
			{
				shieldErrorReported = true;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] Input shield: " + ex.Message));
			}
		}
	}

	private void ConsumePanelMouseEvent(Rect drawnRect)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected I4, but got Unknown
		//IL_003b: 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_0036: Invalid comparison between Unknown and I4
		Event current = Event.current;
		if (current == null)
		{
			return;
		}
		EventType type = current.type;
		switch ((int)type)
		{
		default:
			if ((int)type != 16)
			{
				break;
			}
			goto case 0;
		case 0:
		case 1:
		case 3:
		case 6:
			if (((Rect)(ref drawnRect)).Contains(current.mousePosition) || ShieldHasCapture())
			{
				current.Use();
			}
			break;
		case 2:
		case 4:
		case 5:
			break;
		}
	}

	private bool DominationHasFlags()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		for (int i = 0; i < assemblies.Length; i++)
		{
			Type type = assemblies[i].GetType("SkyfallDomination.Plugin", throwOnError: false);
			if (type == null)
			{
				continue;
			}
			FieldInfo field = type.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo field2 = type.GetField("flags", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (!(field == null) && !(field2 == null))
			{
				object value = field.GetValue(null);
				if (value != null && field2.GetValue(value) is ICollection { Count: >0 })
				{
					return true;
				}
			}
		}
		return false;
	}

	private void SyncScene()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		int handle = ((Scene)(ref activeScene)).handle;
		if (handle != sceneHandle)
		{
			ResetRound();
			ClearObjectiveFlags();
			customCosts.Clear();
			sceneHandle = handle;
			previousPhase = -1;
			costStatus = "Alt + click or drag to select units.";
		}
	}

	private static void BeforeStateChange(GameState __0)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected I4, but got Unknown
		Plugin plugin = instance;
		if ((Object)(object)plugin == (Object)null || !plugin.ready)
		{
			return;
		}
		try
		{
			plugin.SyncScene();
			BaseGameMode val = Mode();
			int num = (int)__0;
			if (num == Phase())
			{
				return;
			}
			if (num == PlacementPhase)
			{
				plugin.ResetRound();
				plugin.previousPhase = PlacementPhase;
			}
			else if (num == BattlePhase && val is SandboxGameMode && plugin.enabledMode.Value && !plugin.armed && !plugin.initializing && !plugin.finished)
			{
				plugin.BeginInitialization();
				if (plugin.initializing)
				{
					plugin.Prepare(val);
				}
			}
		}
		catch (Exception e)
		{
			plugin.Fail(e);
		}
	}

	private static bool BeforeWinner(BaseGameMode __instance)
	{
		Plugin plugin = instance;
		if ((Object)(object)plugin == (Object)null || !plugin.ready || plugin.nativeFinish || plugin.finished || !(__instance is SandboxGameMode))
		{
			return true;
		}
		try
		{
			if (Phase() != BattlePhase)
			{
				return true;
			}
			return !plugin.armed && (!plugin.initializing || !(Time.unscaledTime <= plugin.initDeadline));
		}
		catch
		{
			return true;
		}
	}

	private void BeginInitialization()
	{
		if (DominationHasFlags())
		{
			finished = true;
			status = "Attrition skipped: another game mode is active.";
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] " + status));
		}
		else
		{
			initializing = true;
			attempts = 0;
			initDeadline = Time.unscaledTime + 3f;
			nextInit = Time.unscaledTime;
		}
	}

	private static string UnitLabel(UnitBlueprint bp)
	{
		object obj;
		if (!((Object)(object)bp == (Object)null) && bp.Entity != null)
		{
			obj = bp.Entity.Name;
			if (obj == null)
			{
				return "Unit";
			}
		}
		else
		{
			obj = "Unit";
		}
		return (string)obj;
	}

	private Dictionary<Unit, Placement> ReadPlacement(BaseGameMode mode)
	{
		//IL_0037: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<Unit, Placement> dictionary = new Dictionary<Unit, Placement>();
		RuntimeReferenceService service = ServiceLocator.GetService<RuntimeReferenceService>();
		if ((Object)(object)service == (Object)null || mode == null || mode.TeamLayouts == null)
		{
			return dictionary;
		}
		Team[] array = (Team[])(object)new Team[2]
		{
			default(Team),
			(Team)1
		};
		foreach (Team val in array)
		{
			List<TABSLayoutUnit> teamLayout = mode.TeamLayouts.GetTeamLayout(val);
			if (teamLayout == null)
			{
				continue;
			}
			foreach (TABSLayoutUnit item in teamLayout)
			{
				if (item != null && item.RuntimeReference != null)
				{
					Unit referenceTarget = service.GetReferenceTarget<Unit>((RuntimeReference)(object)item.RuntimeReference);
					if (!((Object)(object)referenceTarget == (Object)null) && !((Object)(object)referenceTarget.unitBlueprint == (Object)null) && referenceTarget.Team == val)
					{
						dictionary[referenceTarget] = new Placement
						{
							Blueprint = referenceTarget.unitBlueprint,
							Team = val,
							Position = item.m_position,
							Rotation = item.GetRotation()
						};
					}
				}
			}
		}
		return dictionary;
	}

	private static bool SameType(Placement a, Placement b)
	{
		//IL_001a: 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)
		if (a != null && b != null && (Object)(object)a.Blueprint == (Object)(object)b.Blueprint)
		{
			return a.Team == b.Team;
		}
		return false;
	}

	private static bool SamePlacement(Placement a, Placement b)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		if (SameType(a, b))
		{
			Vector3 val = a.Position - b.Position;
			if (((Vector3)(ref val)).sqrMagnitude <= 0.0225f)
			{
				return Quaternion.Angle(a.Rotation, b.Rotation) <= 10f;
			}
		}
		return false;
	}

	private void ReconcileCosts(Dictionary<Unit, Placement> available)
	{
		boundCosts.Clear();
		foreach (CostPick customCost in customCosts)
		{
			if ((Object)(object)customCost.Bound != (Object)null && available.TryGetValue(customCost.Bound, out var value) && SameType(customCost.Original, value) && !boundCosts.ContainsKey(customCost.Bound))
			{
				customCost.Original = value;
				boundCosts.Add(customCost.Bound, customCost);
			}
			else
			{
				customCost.Bound = null;
			}
		}
		foreach (CostPick customCost2 in customCosts)
		{
			if ((Object)(object)customCost2.Bound != (Object)null)
			{
				continue;
			}
			Unit match = null;
			int num = 0;
			foreach (KeyValuePair<Unit, Placement> item in available)
			{
				if (!boundCosts.ContainsKey(item.Key) && SamePlacement(customCost2.Original, item.Value))
				{
					match = item.Key;
					num++;
					if (num > 1)
					{
						break;
					}
				}
			}
			if (num == 1 && customCosts.Count((CostPick p) => (Object)(object)p.Bound == (Object)null && SamePlacement(p.Original, available[match])) == 1)
			{
				customCost2.Bound = match;
				customCost2.Original = available[match];
				boundCosts.Add(match, customCost2);
			}
		}
	}

	private void RefreshPlacement(BaseGameMode mode)
	{
		placementCache = ReadPlacement(mode);
		ReconcileCosts(placementCache);
		selected.RemoveWhere((Unit u) => (Object)(object)u == (Object)null || !placementCache.ContainsKey(u));
	}

	private static Camera PlacementCamera()
	{
		Camera main = Camera.main;
		if (!((Object)(object)main != (Object)null))
		{
			return ((IEnumerable<Camera>)Camera.allCameras).FirstOrDefault((Func<Camera, bool>)((Camera x) => (Object)(object)x != (Object)null && ((Behaviour)x).enabled));
		}
		return main;
	}

	private int EffectiveCost(Unit unit)
	{
		if (!boundCosts.TryGetValue(unit, out var value))
		{
			return 1;
		}
		return value.Cost;
	}

	private float MenuHeight(int phase)
	{
		if (phase == PlacementPhase)
		{
			return menuTab switch
			{
				1 => 330f, 
				2 => 326f, 
				3 => 446f, 
				_ => 270f, 
			};
		}
		return (showBattleDetails ? 304f : 190f) + (roundFlags ? 58f : 0f);
	}

	private float MenuScale(float height)
	{
		return Mathf.Min(1.12f, Mathf.Min(Mathf.Max(1f, (float)Screen.width - 24f) / 420f, Mathf.Max(1f, (float)Screen.height - 24f) / height));
	}

	private Rect PanelRect()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		float num = MenuHeight(Phase());
		float num2 = MenuScale(num);
		float num3 = 420f * num2;
		return new Rect(Mathf.Max(0f, (float)Screen.width - num3 - 12f), 12f, num3, num * num2);
	}

	private void ToggleSelected(BaseGameMode mode, Vector2 point)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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_0025: 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_0052: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(point.x, (float)Screen.height - point.y, 0f);
		Rect val2 = PanelRect();
		if (((Rect)(ref val2)).Contains(point))
		{
			return;
		}
		Camera val3 = PlacementCamera();
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		RefreshPlacement(mode);
		Unit val4 = null;
		float num = float.MaxValue;
		RaycastHit[] array = Physics.RaycastAll(val3.ScreenPointToRay(val), 10000f, -5, (QueryTriggerInteraction)2);
		for (int i = 0; i < array.Length; i++)
		{
			RaycastHit val5 = array[i];
			if (!((Object)(object)((RaycastHit)(ref val5)).collider == (Object)null))
			{
				Unit componentInParent = ((Component)((RaycastHit)(ref val5)).collider).GetComponentInParent<Unit>();
				if ((Object)(object)componentInParent != (Object)null && placementCache.ContainsKey(componentInParent) && ((RaycastHit)(ref val5)).distance < num)
				{
					val4 = componentInParent;
					num = ((RaycastHit)(ref val5)).distance;
				}
			}
		}
		if ((Object)(object)val4 == (Object)null)
		{
			float num2 = 1764f;
			foreach (KeyValuePair<Unit, Placement> item in placementCache)
			{
				Unit key = item.Key;
				if ((Object)(object)key == (Object)null)
				{
					continue;
				}
				Vector3 val6 = (((Object)(object)key.data != (Object)null && (Object)(object)key.data.mainRig != (Object)null) ? key.data.mainRig.position : ((Component)key).transform.position);
				Vector3 val7 = val3.WorldToScreenPoint(val6 + Vector3.up * 1.25f);
				if (!(val7.z <= 0f))
				{
					Vector2 val8 = new Vector2(val7.x - val.x, val7.y - val.y);
					float sqrMagnitude = ((Vector2)(ref val8)).sqrMagnitude;
					if (sqrMagnitude < num2)
					{
						val4 = key;
						num2 = sqrMagnitude;
					}
				}
			}
		}
		if ((Object)(object)val4 == (Object)null)
		{
			costStatus = "No placed unit selected.";
			return;
		}
		if (!selected.Remove(val4))
		{
			if (selected.Count == 0)
			{
				editCost = Mathf.Clamp(EffectiveCost(val4), 1, 25);
			}
			selected.Add(val4);
		}
		costStatus = selected.Count + " selected. Set cost and press Apply.";
	}

	private static Vector2 MouseGuiPoint()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: 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: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		Vector3 mousePosition = Input.mousePosition;
		return new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y);
	}

	private static Rect DragRect(Vector2 a, Vector2 b)
	{
		//IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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)
		return Rect.MinMaxRect(Mathf.Min(a.x, b.x), Mathf.Min(a.y, b.y), Mathf.Max(a.x, b.x), Mathf.Max(a.y, b.y));
	}

	private static bool PointerOverNativeUI()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//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_0041: Unknown result type (might be due to invalid IL or missing references)
		EventSystem current = EventSystem.current;
		if ((Object)(object)current == (Object)null)
		{
			return false;
		}
		PointerEventData val = new PointerEventData(current);
		val.position = Vector2.op_Implicit(Input.mousePosition);
		List<RaycastResult> list = new List<RaycastResult>();
		current.RaycastAll(val, list);
		if (list.Count > 0)
		{
			return list[0].module is GraphicRaycaster;
		}
		return false;
	}

	private void UpdateDragSelection(BaseGameMode mode)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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)
		//IL_007d: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_00b8: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: 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)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		if (!placementGuardReady)
		{
			dragSelecting = false;
			return;
		}
		Vector2 val = MouseGuiPoint();
		Vector2 val3;
		if (!dragSelecting)
		{
			if (AltHeld() && Input.GetMouseButtonDown(0) && !ShieldHasCapture())
			{
				Rect val2 = PanelRect();
				if (!((Rect)(ref val2)).Contains(val) && !PointerOverNativeUI())
				{
					dragSelecting = true;
					val3 = (dragStart = (dragEnd = val));
				}
			}
			return;
		}
		dragEnd = val;
		if (Input.GetMouseButtonUp(0))
		{
			dragSelecting = false;
			val3 = dragEnd - dragStart;
			if (((Vector2)(ref val3)).sqrMagnitude < 64f)
			{
				ToggleSelected(mode, dragStart);
			}
			else
			{
				SelectBox(mode, DragRect(dragStart, dragEnd));
			}
		}
		else if (!Input.GetMouseButton(0))
		{
			dragSelecting = false;
		}
	}

	private void SelectBox(BaseGameMode mode, Rect box)
	{
		//IL_0072: 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_008d: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: 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_0085: 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_00ca: 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)
		//IL_00e5: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: 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_0129: Unknown result type (might be due to invalid IL or missing references)
		Camera val = PlacementCamera();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		RefreshPlacement(mode);
		int num = 0;
		Vector2 val4 = default(Vector2);
		foreach (KeyValuePair<Unit, Placement> item in placementCache)
		{
			Unit key = item.Key;
			if ((Object)(object)key == (Object)null)
			{
				continue;
			}
			Vector3 val2 = (((Object)(object)key.data != (Object)null && (Object)(object)key.data.mainRig != (Object)null) ? key.data.mainRig.position : ((Component)key).transform.position);
			Vector3 val3 = val.WorldToScreenPoint(val2 + Vector3.up * 1.25f);
			if (val3.z <= 0f)
			{
				continue;
			}
			((Vector2)(ref val4))..ctor(val3.x, (float)Screen.height - val3.y);
			if (!((Rect)(ref box)).Contains(val4) || val4.x < 0f || val4.x >= (float)Screen.width || val4.y < 0f || val4.y >= (float)Screen.height)
			{
				continue;
			}
			Rect val5 = PanelRect();
			if (!((Rect)(ref val5)).Contains(val4))
			{
				if (selected.Count == 0)
				{
					editCost = Mathf.Clamp(EffectiveCost(key), 1, 25);
				}
				if (selected.Add(key))
				{
					num++;
				}
			}
		}
		costStatus = num + " added; " + selected.Count + " selected. Press Apply to set cost.";
	}

	private void DrawSelectionBox()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0047: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		if (dragSelecting && (int)Event.current.type == 7)
		{
			Vector2 val = dragEnd - dragStart;
			if (!(((Vector2)(ref val)).sqrMagnitude < 64f))
			{
				Rect val2 = DragRect(dragStart, dragEnd);
				GUI.DrawTexture(val2, (Texture)(object)selectionFill);
				GUI.DrawTexture(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width, 2f), (Texture)(object)selectionBorder);
				GUI.DrawTexture(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).yMax - 2f, ((Rect)(ref val2)).width, 2f), (Texture)(object)selectionBorder);
				GUI.DrawTexture(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, 2f, ((Rect)(ref val2)).height), (Texture)(object)selectionBorder);
				GUI.DrawTexture(new Rect(((Rect)(ref val2)).xMax - 2f, ((Rect)(ref val2)).y, 2f, ((Rect)(ref val2)).height), (Texture)(object)selectionBorder);
			}
		}
	}

	private void OnApplicationFocus(bool focus)
	{
		if (!focus)
		{
			dragSelecting = false;
			altMouseCaptured = false;
			gestureReleaseFrame = -1;
		}
	}

	private void ApplyCost(bool clear)
	{
		if (Phase() != PlacementPhase || !enabledMode.Value)
		{
			return;
		}
		RefreshPlacement(Mode());
		int num = 0;
		foreach (Unit item in selected)
		{
			if (!((Object)(object)item == (Object)null) && placementCache.TryGetValue(item, out var value))
			{
				if (boundCosts.TryGetValue(item, out var value2))
				{
					customCosts.Remove(value2);
				}
				if (!clear)
				{
					customCosts.Add(new CostPick
					{
						Bound = item,
						Original = value,
						Cost = Mathf.Clamp(editCost, 1, 25)
					});
				}
				num++;
			}
		}
		ReconcileCosts(placementCache);
		costStatus = (clear ? ("Cleared overrides on " + num + " selected units.") : ("Set " + num + " selected units to " + editCost + " tickets."));
	}

	private void DrawCostEditor()
	{
		//IL_0014: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0446: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(R(12f, 103f, 396f, 18f), "Alt + click: toggle unit | Alt + drag: select multiple", menuHelp);
		GUI.Label(R(12f, 122f, 396f, 18f), "Selected: " + selected.Count + "  |  Custom costs: " + boundCosts.Count, menuLabel);
		string text = "Select units to edit their replacement cost.";
		if (selected.Count == 1)
		{
			Unit val = selected.First();
			if ((Object)(object)val != (Object)null && placementCache.TryGetValue(val, out var value))
			{
				text = UnitLabel(value.Blueprint) + "  |  " + EffectiveCost(val) + " tickets";
			}
		}
		else if (selected.Count > 1)
		{
			int[] array = (from x in (from u in selected
					where (Object)(object)u != (Object)null && placementCache.ContainsKey(u)
					select EffectiveCost(u)).Distinct()
				orderby x
				select x).ToArray();
			if (array.Length != 0)
			{
				text = "Current costs: " + ((array.Length == 1) ? array[0].ToString() : (array.First() + "-" + array.Last())) + " tickets";
			}
		}
		GUI.Label(R(12f, 141f, 396f, 30f), text, menuHelp);
		GUI.Box(R(12f, 172f, 396f, 58f), GUIContent.none, neutralCard);
		GUI.Label(R(20f, 175f, 132f, 22f), "Cost: " + editCost + " tickets", menuLabel);
		if (Btn(153f, 175f, 26f, "-"))
		{
			editCost = Mathf.Max(1, editCost - 1);
		}
		editCost = Mathf.Clamp(Mathf.RoundToInt(GUI.HorizontalSlider(R(185f, 181f, 185f, 16f), (float)editCost, 1f, 25f)), 1, 25);
		if (Btn(374f, 175f, 26f, "+"))
		{
			editCost = Mathf.Min(25, editCost + 1);
		}
		bool enabled = GUI.enabled;
		GUI.enabled = enabled && selected.Count > 0;
		if (Btn(20f, 202f, 188f, "Apply to selected"))
		{
			ApplyCost(clear: false);
		}
		if (Btn(212f, 202f, 188f, "Restore default"))
		{
			ApplyCost(clear: true);
		}
		GUI.enabled = enabled;
		if (confirmCostReset)
		{
			if (Btn(12f, 234f, 196f, "Yes, reset ALL costs"))
			{
				customCosts.Clear();
				boundCosts.Clear();
				confirmCostReset = false;
				costStatus = "All custom costs reset to default.";
			}
			if (Btn(212f, 234f, 196f, "Cancel reset"))
			{
				confirmCostReset = false;
			}
		}
		else
		{
			if (Btn(12f, 234f, 196f, "Deselect all"))
			{
				selected.Clear();
				costStatus = "Selection cleared. Costs kept.";
			}
			if (Btn(212f, 234f, 196f, "Reset ALL costs"))
			{
				confirmCostReset = true;
			}
		}
		int num = customCosts.Count - boundCosts.Count;
		if (num > 0)
		{
			GUI.Label(R(12f, 260f, 204f, 20f), "Unmatched: " + num + " (not charged)", menuHelp);
			if (Btn(220f, 258f, 188f, "Remove missing"))
			{
				customCosts.RemoveAll((CostPick p) => (Object)(object)p.Bound == (Object)null);
				costStatus = "Missing assignments removed.";
			}
		}
		GUI.Label(R(12f, 282f, 396f, 26f), confirmCostReset ? "Remove all manual costs? Team budgets stay the same." : costStatus, menuHelp);
	}

	private void DrawPlacementLabels()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_001f: 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_0098: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_00e2: 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_0151: 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 ((int)Event.current.type != 7)
		{
			return;
		}
		Camera val = PlacementCamera();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Rect val2 = PanelRect();
		Rect val5 = default(Rect);
		foreach (Unit item in selected.Concat(boundCosts.Keys).Distinct())
		{
			if ((Object)(object)item == (Object)null || !placementCache.TryGetValue(item, out var _))
			{
				continue;
			}
			Vector3 val3 = (((Object)(object)item.data != (Object)null && (Object)(object)item.data.mainRig != (Object)null) ? item.data.mainRig.position : ((Component)item).transform.position);
			Vector3 val4 = val.WorldToScreenPoint(val3 + Vector3.up * 1.8f);
			if (!(val4.z <= 0f))
			{
				((Rect)(ref val5))..ctor(val4.x - 37f, (float)Screen.height - val4.y - 13f, 74f, 25f);
				if (!(((Rect)(ref val5)).xMax < 0f) && !(((Rect)(ref val5)).xMin > (float)Screen.width) && !(((Rect)(ref val5)).yMax < 0f) && !(((Rect)(ref val5)).yMin > (float)Screen.height) && !((Rect)(ref val2)).Overlaps(val5))
				{
					bool flag = selected.Contains(item);
					GUI.Box(val5, (flag ? "> " : "") + EffectiveCost(item) + "t" + (flag ? " <" : ""));
				}
			}
		}
	}

	private void Prepare(BaseGameMode mode)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: 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_0132: 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_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		attempts++;
		slots.Clear();
		armed = false;
		try
		{
			RuntimeReferenceService service = ServiceLocator.GetService<RuntimeReferenceService>();
			if ((Object)(object)service == (Object)null || mode.TeamLayouts == null)
			{
				throw new InvalidOperationException("Layout/reference service unavailable");
			}
			HashSet<int> hashSet = new HashSet<int>();
			float delay = Clamp(respawnDelay.Value, 1f, 120f, 10f);
			Team[] array = (Team[])(object)new Team[2]
			{
				default(Team),
				(Team)1
			};
			foreach (Team val in array)
			{
				List<TABSLayoutUnit> teamLayout = mode.TeamLayouts.GetTeamLayout(val);
				if (teamLayout == null)
				{
					continue;
				}
				foreach (TABSLayoutUnit item in teamLayout)
				{
					if (item != null)
					{
						if (item.RuntimeReference == null)
						{
							throw new InvalidOperationException("Original layout entry lacks runtime reference");
						}
						Unit referenceTarget = service.GetReferenceTarget<Unit>((RuntimeReference)(object)item.RuntimeReference);
						if ((Object)(object)referenceTarget == (Object)null || (Object)(object)referenceTarget.unitBlueprint == (Object)null)
						{
							throw new InvalidOperationException("Original unit reference did not resolve");
						}
						if (hashSet.Add(((Object)referenceTarget).GetInstanceID()))
						{
							Slot slot = new Slot
							{
								Blueprint = referenceTarget.unitBlueprint,
								Current = referenceTarget,
								Team = val,
								Position = item.m_position,
								Rotation = item.GetRotation(),
								Number = slots.Count + 1,
								State = SlotState.Active
							};
							slot.Cost = 1;
							slot.Delay = delay;
							slots.Add(slot);
						}
					}
				}
			}
			if (!slots.Any((Slot s) => (int)s.Team == 0) || !slots.Any((Slot s) => (int)s.Team == 1))
			{
				throw new InvalidOperationException("Both teams need preplaced units");
			}
			Dictionary<Unit, Placement> available = slots.ToDictionary((Slot s) => s.Current, (Slot s) => new Placement
			{
				Blueprint = s.Blueprint,
				Team = s.Team,
				Position = s.Position,
				Rotation = s.Rotation
			});
			ReconcileCosts(available);
			foreach (Slot slot2 in slots)
			{
				if (boundCosts.TryGetValue(slot2.Current, out var value))
				{
					slot2.Cost = Mathf.Clamp(value.Cost, 1, 25);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] Custom cost slot=" + slot2.Number + " team=" + ((object)Unsafe.As<Team, Team>(ref slot2.Team)/*cast due to .constrained prefix*/).ToString() + " unit=" + UnitLabel(slot2.Blueprint) + " cost=" + slot2.Cost));
				}
			}
			if (customCosts.Count > boundCosts.Count)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] " + (customCosts.Count - boundCosts.Count) + " custom cost assignments unmatched; no override applied to those slots."));
			}
			int num = Mathf.Clamp(redTickets.Value, 0, 100000);
			int tickets = (separateTickets.Value ? Mathf.Clamp(blueTickets.Value, 0, 100000) : num);
			red = new Side(num);
			blue = new Side(tickets);
			InitializeFlags();
			roundWaves = waveMode.Value;
			roundWave = Clamp(waveInterval.Value, 1f, 120f, 15f);
			cycleEnabled = suddenDeath.Value;
			roundCooldown = Clamp(cooldown.Value, 1f, 1800f, 120f);
			roundDuration = Clamp(duration.Value, 1f, 1800f, 30f);
			armed = true;
			initializing = false;
			status = "Ready: " + slots.Count + " original slots";
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] " + status + " R=" + num + " B=" + tickets + " waves=" + roundWaves + " | " + string.Join(", ", (from s in slots
				group s by s.Cost + "t/" + s.Delay.ToString("F1") + "s" into g
				select g.Key + " x" + g.Count()).ToArray())));
		}
		catch (Exception ex)
		{
			slots.Clear();
			armed = false;
			status = "Initialization attempt " + attempts + ": " + ex.Message;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] " + status));
		}
	}

	private void ResetRound()
	{
		armed = (initializing = (running = (finished = (nativeFinish = false))));
		ResetFlagRound();
		cycleEnabled = (spawnBlocked = false);
		nextPhase = 0f;
		slots.Clear();
		red = (blue = null);
		attempts = 0;
		nextTick = (nextReport = (finalElapsed = 0f));
		dragSelecting = false;
		selected.Clear();
		boundCosts.Clear();
		placementCache.Clear();
		nextPlacementRefresh = 0f;
		foreach (CostPick customCost in customCosts)
		{
			customCost.Bound = null;
		}
		status = "Enable Attrition in placement to start.";
	}

	private void Fail(Exception e)
	{
		((BaseUnityPlugin)this).Logger.LogError((object)("[Attrition] " + e));
		armed = (initializing = (running = false));
		finished = true;
		FlagRunnerManager.Reset();
		status = "Stopped; native victory restored: " + e.Message;
	}

	private void Update()
	{
		if (!ready)
		{
			return;
		}
		try
		{
			SyncScene();
			BaseGameMode val = Mode();
			int num = Phase();
			if (!(val is SandboxGameMode))
			{
				if (flags.Count > 0)
				{
					ClearObjectiveFlags();
				}
				dragSelecting = false;
				if (armed || initializing || finished)
				{
					ResetRound();
				}
				previousPhase = num;
				return;
			}
			TrackAltMouse();
			if (AltHeld() && Input.GetKeyDown((KeyCode)106))
			{
				panel = !panel;
				RefreshInputShield();
			}
			if (num != BattlePhase)
			{
				if (num == PlacementPhase && previousPhase != PlacementPhase)
				{
					ResetRound();
				}
				previousPhase = num;
				if (num == PlacementPhase)
				{
					UpdateFlagPlacement();
				}
				if (num == PlacementPhase && enabledMode.Value && panel)
				{
					if (Time.unscaledTime >= nextPlacementRefresh)
					{
						nextPlacementRefresh = Time.unscaledTime + 0.35f;
						RefreshPlacement(val);
					}
					UpdateDragSelection(val);
				}
				else
				{
					dragSelecting = false;
					selected.Clear();
				}
				return;
			}
			dragSelecting = false;
			if (previousPhase != BattlePhase && enabledMode.Value && !armed && !initializing && !finished)
			{
				BeginInitialization();
			}
			previousPhase = num;
			if (initializing)
			{
				if (Time.unscaledTime > initDeadline)
				{
					initializing = false;
					finished = true;
					status = "Attrition unavailable; layout initialization timed out. Native victory restored.";
					((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] " + status));
				}
				else if (Time.unscaledTime >= nextInit)
				{
					nextInit = Time.unscaledTime + 0.25f;
					Prepare(val);
				}
			}
			if (!armed || finished)
			{
				return;
			}
			if (!running)
			{
				running = true;
				startTime = Time.time;
				spawnBlocked = false;
				nextPhase = startTime + roundCooldown;
				nextTick = startTime;
				nextReport = startTime + 5f;
				status = "Attrition running";
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[Attrition] Round started.");
			}
			if (cycleEnabled && Time.time >= nextPhase)
			{
				float num2 = roundCooldown + roundDuration;
				float num3 = (Time.time - startTime) % num2;
				bool flag = num3 >= roundCooldown;
				nextPhase = Time.time + (flag ? (num2 - num3) : (roundCooldown - num3));
				if (spawnBlocked != flag)
				{
					spawnBlocked = flag;
					status = (flag ? "SUDDEN DEATH - reinforcements suspended" : "Reinforcements resumed");
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] " + status));
				}
			}
			if (Time.time < nextTick || Time.timeScale <= 0f)
			{
				return;
			}
			nextTick = Time.time + 0.2f;
			CheckVictory(val);
			if (!finished)
			{
				TickObjectives();
				TickSlots();
				if (armed && Time.time >= nextReport)
				{
					nextReport = Time.time + 5f;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] R=" + red.Tickets + " B=" + blue.Tickets + " pending R=" + Pending((Team)0) + " B=" + Pending((Team)1)));
				}
			}
		}
		catch (Exception e)
		{
			Fail(e);
		}
	}

	private void Schedule(Slot s)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		Side side = Account(s.Team);
		side.Losses++;
		if ((Object)(object)s.Current == (Object)null || ((Object)(object)s.Current.data != (Object)null && s.Current.data.Dead))
		{
			s.Current = null;
		}
		if (side.Tickets < s.Cost)
		{
			s.State = SlotState.Retired;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] Retired slot=" + s.Number + " team=" + ((object)Unsafe.As<Team, Team>(ref s.Team)/*cast due to .constrained prefix*/).ToString() + " insufficient tickets=" + side.Tickets + " cost=" + s.Cost));
			return;
		}
		side.Tickets -= s.Cost;
		s.Reserved = s.Cost;
		s.Due = Time.time + s.Delay;
		if (roundWaves)
		{
			s.Due = startTime + Mathf.Ceil((s.Due - startTime) / roundWave) * roundWave;
		}
		s.State = SlotState.Queued;
		AssignNewReinforcement(s);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] Reserved slot=" + s.Number + " team=" + ((object)Unsafe.As<Team, Team>(ref s.Team)/*cast due to .constrained prefix*/).ToString() + " cost=" + s.Cost + " left=" + side.Tickets + " due=" + (s.Due - startTime).ToString("F1")));
	}

	private void Refund(Slot s)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		if (s.Reserved > 0)
		{
			Account(s.Team).Tickets += s.Reserved;
			s.Reserved = 0;
		}
	}

	private void Confirm(Slot s)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		s.Reserved = 0;
		s.State = SlotState.Active;
		Account(s.Team).Replacements++;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] Respawn confirmed slot=" + s.Number + " team=" + ((object)Unsafe.As<Team, Team>(ref s.Team)/*cast due to .constrained prefix*/).ToString()));
	}

	private void SpawnFailed(Slot s, string reason)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Refund(s);
		s.State = SlotState.Retired;
		Account(s.Team).Failed++;
		((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] Disabled slot=" + s.Number + "; reserved tickets refunded; " + reason));
	}

	private void TickSlots()
	{
		//IL_01af: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		foreach (Slot slot2 in slots)
		{
			switch (slot2.State)
			{
			case SlotState.Active:
				if (!Alive(slot2.Current))
				{
					Schedule(slot2);
				}
				break;
			case SlotState.Queued:
				if (Alive(slot2.Current))
				{
					Refund(slot2);
					Account(slot2.Team).Losses--;
					slot2.State = SlotState.Active;
				}
				break;
			case SlotState.Activating:
				if (Alive(slot2.Current))
				{
					Confirm(slot2);
				}
				else if (Time.time >= slot2.Due)
				{
					SpawnFailed(slot2, "Native unit did not activate");
				}
				break;
			case SlotState.Retired:
				if (Alive(slot2.Current))
				{
					slot2.State = SlotState.Active;
				}
				break;
			}
		}
		if (spawnBlocked)
		{
			return;
		}
		int count = Mathf.Clamp(maxSpawns.Value, 1, 16);
		Slot[] array = (from x in slots
			where x.State == SlotState.Queued && !x.FlagHeld && Time.time >= x.Due
			orderby x.Due, x.Number
			select x).Take(count).ToArray();
		foreach (Slot slot in array)
		{
			if (Alive(slot.Current))
			{
				Refund(slot);
				Account(slot.Team).Losses--;
				slot.State = SlotState.Active;
				continue;
			}
			try
			{
				GameObject[] array2 = slot.Blueprint.Spawn(slot.Position, slot.Rotation, slot.Team, 1f, (UnitPoolInfo?)null);
				Unit val = null;
				if (array2 != null)
				{
					GameObject[] array3 = array2;
					foreach (GameObject val2 in array3)
					{
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						Unit[] componentsInChildren = val2.GetComponentsInChildren<Unit>(true);
						foreach (Unit val3 in componentsInChildren)
						{
							if ((Object)(object)val3 != (Object)null && (Object)(object)val3.unitBlueprint == (Object)(object)slot.Blueprint && val3.Team == slot.Team)
							{
								val = val3;
								break;
							}
						}
						if ((Object)(object)val != (Object)null)
						{
							break;
						}
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("Native Spawn returned no matching unit");
				}
				foreach (Slot slot3 in slots)
				{
					if (slot3 != slot && !((Object)(object)slot3.Current != (Object)(object)val))
					{
						if (slot3.State == SlotState.Active || slot3.State == SlotState.Activating)
						{
							throw new InvalidOperationException("Native Spawn returned an already-owned active unit");
						}
						slot3.Current = null;
					}
				}
				slot.Current = val;
				if (Alive(val))
				{
					Confirm(slot);
					continue;
				}
				slot.State = SlotState.Activating;
				slot.Due = Time.time + 2f;
			}
			catch (Exception ex)
			{
				SpawnFailed(slot, ex.ToString());
			}
		}
	}

	private int Pending(Team t)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return slots.Count((Slot s) => s.Team == t && (s.State == SlotState.Queued || s.State == SlotState.Activating));
	}

	private int Living(Team t)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return slots.Count((Slot s) => s.Team == t && Alive(s.Current));
	}

	private unsafe void CheckVictory(BaseGameMode mode)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Invalid comparison between Unknown and I4
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Living((Team)0) > 0;
		bool flag2 = Living((Team)1) > 0;
		if (flag && flag2)
		{
			return;
		}
		Unit[] array = Object.FindObjectsOfType<Unit>();
		foreach (Unit val in array)
		{
			if (Alive(val))
			{
				if ((int)val.Team == 0)
				{
					flag = true;
				}
				else if ((int)val.Team == 1)
				{
					flag2 = true;
				}
				if (flag && flag2)
				{
					return;
				}
			}
		}
		if (!flag && !flag2)
		{
			finalElapsed = Time.time - startTime;
			armed = (running = false);
			finished = true;
			FlagRunnerManager.Reset();
			status = "Both armies exhausted; native tie handling restored.";
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] " + status));
			return;
		}
		Team val2 = (Team)(!flag);
		finalElapsed = Time.time - startTime;
		nativeFinish = true;
		finished = true;
		armed = (running = false);
		FlagRunnerManager.Reset();
		status = ((object)(*(Team*)(&val2))/*cast due to .constrained prefix*/).ToString() + " wins Attrition";
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[Attrition] " + status + " | R tickets=" + red.Tickets + " losses=" + red.Losses + " respawns=" + red.Replacements + " | B tickets=" + blue.Tickets + " losses=" + blue.Losses + " respawns=" + blue.Replacements));
		try
		{
			decide.Invoke(mode, new object[2] { val2, "Attrition" });
		}
		finally
		{
			nativeFinish = false;
		}
	}

	private Texture2D UiTexture(Color color)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
		((Object)val).hideFlags = (HideFlags)61;
		val.SetPixel(0, 0, color);
		val.Apply();
		uiTextures.Add(val);
		return val;
	}

	private GUIStyle TextStyle(int size, Color ink, bool bold = false, bool wrap = false)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_0023: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = size,
			fontStyle = (FontStyle)(bold ? 1 : 0),
			wordWrap = wrap
		};
		val.normal.textColor = ink;
		return val;
	}

	private GUIStyle CardStyle(Texture2D bg, int pad)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0039: 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_0048: Expected O, but got Unknown
		//IL_0049: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.box);
		val.normal.background = bg;
		val.border = new RectOffset(0, 0, 0, 0);
		val.padding = new RectOffset(pad, pad, pad, pad);
		val.margin = new RectOffset(3, 3, 3, 3);
		return val;
	}

	private void SetButtonState(GUIStyleState state, Texture2D bg, Color ink)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		state.background = bg;
		state.textColor = ink;
	}

	private void EnsureMenuStyles()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Expected O, but got Unknown
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Expected O, but got Unknown
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Expected O, but got Unknown
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Expected O, but got Unknown
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Expected O, but got Unknown
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Expected O, but got Unknown
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Expected O, but got Unknown
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Unknown result type (might be due to invalid IL or missing references)
		//IL_0482: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		if (menuPanel == null)
		{
			Color val = default(Color);
			((Color)(ref val))..ctor(0.94f, 0.96f, 0.99f);
			Color ink = default(Color);
			((Color)(ref ink))..ctor(0.66f, 0.71f, 0.78f);
			menuPanel = CardStyle(UiTexture(new Color(0.09f, 0.11f, 0.14f, 0.98f)), 12);
			neutralCard = CardStyle(UiTexture(new Color(0.14f, 0.16f, 0.2f)), 10);
			redCard = CardStyle(UiTexture(new Color(0.19f, 0.13f, 0.15f)), 10);
			blueCard = CardStyle(UiTexture(new Color(0.12f, 0.17f, 0.25f)), 10);
			menuHeading = TextStyle(12, ink, bold: true);
			menuHelp = TextStyle(12, ink, bold: false, wrap: true);
			menuTitle = TextStyle(19, val, bold: true);
			menuLabel = TextStyle(13, val, bold: false, wrap: true);
			redLabel = TextStyle(13, RedInk, bold: true);
			blueLabel = TextStyle(13, BlueInk, bold: true);
			redNumber = TextStyle(25, RedInk, bold: true);
			blueNumber = TextStyle(25, BlueInk, bold: true);
			statValue = TextStyle(13, val, bold: true);
			statValue.alignment = (TextAnchor)5;
			Texture2D bg = UiTexture(new Color(0.19f, 0.22f, 0.27f));
			Texture2D bg2 = UiTexture(new Color(0.25f, 0.3f, 0.37f));
			Texture2D val2 = UiTexture(new Color(0.31f, 0.39f, 0.51f));
			menuButton = new GUIStyle(GUI.skin.button);
			menuButton.border = new RectOffset(0, 0, 0, 0);
			menuButton.fontSize = 13;
			menuButton.padding = new RectOffset(6, 6, 3, 3);
			menuButton.fixedHeight = 0f;
			SetButtonState(menuButton.normal, bg, val);
			SetButtonState(menuButton.hover, bg2, val);
			SetButtonState(menuButton.active, val2, val);
			SetButtonState(menuButton.focused, bg2, val);
			activeButton = new GUIStyle(menuButton);
			activeButton.normal.background = val2;
			menuField = new GUIStyle(GUI.skin.textField);
			menuField.fontSize = 15;
			menuField.fixedHeight = 0f;
			menuField.border = new RectOffset(0, 0, 0, 0);
			Texture2D bg3 = UiTexture(new Color(0.075f, 0.09f, 0.12f));
			SetButtonState(menuField.normal, bg3, val);
			SetButtonState(menuField.focused, bg3, val);
			SetButtonState(menuField.hover, bg3, val);
			SetButtonState(menuField.active, bg3, val);
			menuToggle = new GUIStyle(GUI.skin.toggle);
			menuToggle.fontSize = 13;
			menuToggle.normal.textColor = val;
			menuToggle.onNormal.textColor = val;
			menuToggle.hover.textColor = val;
			menuToggle.onHover.textColor = val;
			menuToggle.active.textColor = val;
			menuToggle.onActive.textColor = val;
			menuToggle.focused.textColor = val;
			menuToggle.onFocused.textColor = val;
			selectionFill = UiTexture(new Color(0.36f, 0.65f, 1f, 0.17f));
			selectionBorder = UiTexture(new Color(0.55f, 0.8f, 1f, 0.95f));
			redTrack = UiTexture(new Color(0.32f, 0.19f, 0.21f));
			blueTrack = UiTexture(new Color(0.16f, 0.25f, 0.37f));
			redFill = UiTexture(new Color(0.9f, 0.36f, 0.39f));
			blueFill = UiTexture(new Color(0.39f, 0.6f, 0.92f));
		}
	}

	private static Rect R(float x, float y, float w, float h)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		return new Rect(x, y, w, h);
	}

	private bool Btn(float x, float y, float w, string text, bool active = false)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return GUI.Button(R(x, y, w, 24f), text, active ? activeButton : menuButton);
	}

	private void SyncTicketDrafts()
	{
		redTicketDraft = redTickets.Value.ToString();
		blueTicketDraft = blueTickets.Value.ToString();
	}

	private void TicketCard(float x, bool isRed, bool editable, ConfigEntry<int> entry, ref string draft)
	{
		//IL_0010: 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_0093: 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_016f: Unknown result type (might be due to invalid IL or missing references)
		GUI.Box(R(x, 101f, 196f, 72f), GUIContent.none, isRed ? redCard : blueCard);
		GUI.Label(R(x + 8f, 104f, 180f, 18f), isRed ? "RED TEAM" : "BLUE TEAM", isRed ? redLabel : blueLabel);
		bool enabled = GUI.enabled;
		GUI.enabled = enabled && editable;
		string text = GUI.TextField(R(x + 8f, 125f, 180f, 24f), editable ? (draft ?? entry.Value.ToString()) : entry.Value.ToString(), menuField);
		if (editable && text != draft)
		{
			draft = text;
			if (int.TryParse(text, out var result) && result >= 0 && result <= 100000)
			{
				entry.Value = result;
			}
		}
		if (GUI.Button(R(x + 8f, 151f, 87f, 19f), "-25", menuButton))
		{
			entry.Value = Mathf.Clamp(entry.Value - 25, 0, 100000);
			draft = entry.Value.ToString();
		}
		if (GUI.Button(R(x + 101f, 151f, 87f, 19f), "+25", menuButton))
		{
			entry.Value = Mathf.Clamp(entry.Value + 25, 0, 100000);
			draft = entry.Value.ToString();
		}
		GUI.enabled = enabled;
	}

	private void DrawMatchTab()
	{
		//IL_0014: 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_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(R(12f, 79f, 154f, 20f), "STARTING TICKETS", menuHeading);
		bool flag = GUI.Toggle(R(226f, 78f, 182f, 22f), separateTickets.Value, "Separate team tickets", menuToggle);
		if (flag != separateTickets.Value)
		{
			if (flag)
			{
				blueTicketDraft = blueTickets.Value.ToString();
			}
			separateTickets.Value = flag;
		}
		TicketCard(12f, isRed: true, editable: true, redTickets, ref redTicketDraft);
		if (separateTickets.Value)
		{
			TicketCard(212f, isRed: false, editable: true, blueTickets, ref blueTicketDraft);
		}
		else
		{
			TicketCard(212f, isRed: false, editable: false, redTickets, ref blueTicketDraft);
		}
		int num = 0;
		int[] array = new int[4] { 100, 250, 500, 1000 };
		for (int i = 0; i < array.Length; i++)
		{
			int num2 = array[i];
			bool active = redTickets.Value == num2 && (!separateTickets.Value || blueTickets.Value == num2);
			if (Btn(12 + num * 100, 178f, 96f, num2.ToString(), active))
			{
				redTickets.Value = num2;
				if (separateTickets.Value)
				{
					blueTickets.Value = num2;
				}
				SyncTicketDrafts();
			}
			num++;
		}
		int result;
		string text = ((int.TryParse(redTicketDraft, out result) && result >= 0 && result <= 100000 && (!separateTickets.Value || (int.TryParse(blueTicketDraft, out result) && result >= 0 && result <= 100000))) ? ((waveMode.Value ? "Waves" : "Individual respawns") + "  |  1 ticket default  |  SD: " + (suddenDeath.Value ? "On" : "Off")) : "Enter 0-100,000; last valid amount is kept.");
		GUI.Label(R(12f, 206f, 396f, 20f), text, menuHelp);
		GUI.Label(R(12f, 225f, 396f, 20f), "Start the battle normally.", menuHelp);
	}

	private void SwitchMenuTab(int tab)
	{
		if (menuTab != tab)
		{
			menuTab = tab;
			confirmCostReset = false;
			GUI.FocusControl("");
		}
	}

	private void DrawUnitCostsTab()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(R(12f, 78f, 396f, 22f), "Default: 1 ticket per unit. Set custom costs below.", menuLabel);
		if (!enabledMode.Value)
		{
			GUI.Label(R(12f, 104f, 396f, 36f), "Enable Attrition above to select placed units.", menuHelp);
		}
		else if (!placementGuardReady)
		{
			GUI.Label(R(12f, 103f, 396f, 55f), "Selection unavailable: placement guard failed. Check BepInEx log.", menuHelp);
		}
		else
		{
			DrawCostEditor();
		}
	}

	private void DelayControl(float y, string label, ConfigEntry<float> entry, float limit, bool editable = true, string suffix = "s")
	{
		//IL_001e: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		bool enabled = GUI.enabled;
		GUI.enabled = enabled && editable;
		GUI.Label(R(12f, y, 144f, 22f), label, menuLabel);
		GUI.Label(R(155f, y, 51f, 22f), entry.Value.ToString("F0") + suffix, statValue);
		if (Btn(211f, y, 25f, "-"))
		{
			entry.Value = Clamp(entry.Value - 1f, 1f, limit, 10f);
		}
		float num = Clamp(entry.Value, 1f, limit, 10f);
		float num2 = GUI.HorizontalSlider(R(242f, y + 6f, 132f, 16f), num, 1f, limit);
		if (!Mathf.Approximately(num2, num))
		{
			entry.Value = Mathf.Clamp(Mathf.RoundToInt(num2), 1, (int)limit);
		}
		if (Btn(382f, y, 26f, "+"))
		{
			entry.Value = Clamp(entry.Value + 1f, 1f, limit, 10f);
		}
		GUI.enabled = enabled;
	}

	private void DrawAdvancedTab()
	{
		//IL_003b: 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_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		DelayControl(79f, "Respawn delay", respawnDelay, 120f);
		waveMode.Value = GUI.Toggle(R(12f, 107f, 396f, 22f), waveMode.Value, "Wave respawns", menuToggle);
		DelayControl(132f, "Wave interval", waveInterval, 120f, waveMode.Value);
		suddenDeath.Value = GUI.Toggle(R(12f, 160f, 396f, 22f), suddenDeath.Value, "Recurring sudden death (pauses respawns)", menuToggle);
		DelayControl(185f, "Time until blackout", cooldown, 1800f, suddenDeath.Value);
		DelayControl(213f, "Blackout duration", duration, 1800f, suddenDeath.Value);
		GUI.Label(R(12f, 243f, 144f, 22f), "Max spawns / tick", menuLabel);
		GUI.Label(R(155f, 243f, 51f, 22f), maxSpawns.Value.ToString(), statValue);
		int num = Mathf.Clamp(maxSpawns.Value, 1, 16);
		int num2 = Mathf.RoundToInt(GUI.HorizontalSlider(R(211f, 249f, 197f, 16f), (float)num, 1f, 16f));
		if (num2 != num)
		{
			maxSpawns.Value = num2;
		}
		GUI.Label(R(12f, 270f, 396f, 22f), "Same delay for all units. Spawn cap per 0.2 game seconds.", menuHelp);
	}

	private void TicketBar(float x, Side side, bool isRed)
	{
		//IL_0010: 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_0086: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Invalid comparison between Unknown and I4
		//IL_0168: 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_0137: Unknown result type (might be due to invalid IL or missing references)
		GUI.Box(R(x, 41f, 196f, 78f), GUIContent.none, isRed ? redCard : blueCard);
		GUI.Label(R(x + 8f, 44f, 180f, 18f), isRed ? "RED TEAM" : "BLUE TEAM", isRed ? redLabel : blueLabel);
		GUI.Label(R(x + 8f, 62f, 180f, 31f), side.Tickets.ToString(), isRed ? redNumber : blueNumber);
		Rect val = R(x + 8f, 94f, 180f, 6f);
		if ((int)Event.current.type == 7)
		{
			GUI.DrawTexture(val, (Texture)(object)(isRed ? redTrack : blueTrack));
			float num = ((side.Starting > 0) ? Mathf.Clamp01((float)side.Tickets / (float)side.Starting) : 0f);
			if (num > 0f)
			{
				GUI.DrawTexture(R(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width * num, ((Rect)(ref val)).height), (Texture)(object)(isRed ? redFill : blueFill));
			}
		}
		GUI.Label(R(x + 8f, 100f, 180f, 16f), side.Tickets + " / " + side.Starting + " tickets", menuHelp);
	}

	private void StatRow(float y, string label, int r, int b)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(R(20f, y, 208f, 20f), label, menuLabel);
		GUI.Label(R(246f, y, 72f, 20f), r.ToString(), redLabel);
		GUI.Label(R(330f, y, 72f, 20f), b.ToString(), blueLabel);
	}

	private void DrawBattlePanel(bool details)
	{
		//IL_0024: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		if (red == null || blue == null)
		{
			GUI.Label(R(12f, 43f, 396f, 80f), status, menuHelp);
			return;
		}
		TicketBar(12f, red, isRed: true);
		TicketBar(212f, blue, isRed: false);
		string text = (finished ? status : ((!running) ? status : (spawnBlocked ? "Reinforcements paused" : "Reinforcements active")));
		GUI.Label(R(12f, 121f, 396f, 20f), text, menuLabel);
		string text2 = ((running && cycleEnabled) ? ((spawnBlocked ? "Resume in " : "Next sudden death in ") + Mathf.CeilToInt(Mathf.Max(0f, nextPhase - Time.time)) + "s") : (roundWaves ? "Wave respawns" : "Individual respawns"));
		GUI.Label(R(12f, 144f, 233f, 24f), text2, menuHelp);
		if (Btn(252f, 143f, 156f, details ? "Hide statistics" : "Show statistics"))
		{
			showBattleDetails = !details;
		}
		if (details)
		{
			GUI.Box(R(12f, 174f, 396f, 108f), GUIContent.none, neutralCard);
			StatRow(177f, "Original units alive", Living((Team)0), Living((Team)1));
			StatRow(197f, "Pending respawns", Pending((Team)0), Pending((Team)1));
			StatRow(217f, "Total losses", red.Losses, blue.Losses);
			StatRow(237f, "Respawned", red.Replacements, blue.Replacements);
			StatRow(257f, "Failed spawns", red.Failed, blue.Failed);
		}
	}

	private void OnGUI()
	{
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_038b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_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)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_00ca: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: 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_0312: Unknown result type (might be due to invalid IL or missing references)
		if (!ready || !panel)
		{
			return;
		}
		try
		{
			int num = Phase();
			if (!MenuVisible(num))
			{
				return;
			}
			EnsureMenuStyles();
			if (num == PlacementPhase && enabledMode.Value)
			{
				DrawSelectionBox();
				DrawPlacementLabels();
			}
			int num2 = menuTab;
			bool flag = showBattleDetails;
			float num3 = MenuHeight(num);
			float num4 = MenuScale(num3);
			Rect drawnRect = PanelRect();
			Matrix4x4 matrix = GUI.matrix;
			try
			{
				GUIUtility.ScaleAroundPivot(new Vector2(num4, num4), new Vector2(((Rect)(ref drawnRect)).x, ((Rect)(ref drawnRect)).y));
				GUI.BeginGroup(R(((Rect)(ref drawnRect)).x, ((Rect)(ref drawnRect)).y, 420f, num3));
				try
				{
					GUI.Box(R(0f, 0f, 420f, num3), GUIContent.none, menuPanel);
					GUI.Label(R(12f, 7f, 139f, 28f), "ATTRITION", menuTitle);
					if (num == PlacementPhase)
					{
						bool value = enabledMode.Value;
						enabledMode.Value = GUI.Toggle(R(152f, 9f, 184f, 24f), enabledMode.Value, "Enable Attrition", menuToggle);
						if (value && !enabledMode.Value)
						{
							dragSelecting = false;
							selected.Clear();
							confirmCostReset = false;
						}
					}
					else if (red != null && blue != null)
					{
						float num5 = (finished ? finalElapsed : Mathf.Max(0f, Time.time - startTime));
						GUI.Label(R(250f, 10f, 79f, 24f), Mathf.FloorToInt(num5 / 60f) + ":" + Mathf.FloorToInt(num5 % 60f).ToString("00"), menuLabel);
					}
					if (Btn(348f, 9f, 60f, "Hide"))
					{
						panel = false;
						dragSelecting = false;
					}
					if (num == PlacementPhase)
					{
						string[] array = new string[4] { "Match", "Unit Costs", "Advanced", "Flags" };
						for (int i = 0; i < array.Length; i++)
						{
							if (Btn(12 + i * 100, 43f, 96f, array[i], num2 == i))
							{
								SwitchMenuTab(i);
							}
						}
						switch (num2)
						{
						case 1:
							DrawUnitCostsTab();
							break;
						case 2:
							DrawAdvancedTab();
							break;
						case 3:
							DrawFlagsTab();
							break;
						default:
							DrawMatchTab();
							break;
						}
						GUI.Label(R(12f, num3 - 20f, 396f, 18f), "Alt + J: show / hide  |  v1.1", menuHelp);
					}
					else
					{
						DrawBattlePanel(flag);
						if (roundFlags)
						{
							DrawFlagHud(flag ? 283 : 169);
						}
						GUI.Label(R(12f, num3 - 20f, 396f, 18f), "Alt + J: show / hide HUD", menuHelp);
					}
				}
				finally
				{
					GUI.EndGroup();
				}
			}
			finally
			{
				GUI.matrix = matrix;
				ConsumePanelMouseEvent(drawnRect);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[Attrition] HUD: " + ex.Message));
			panel = false;
		}
	}

	private void OnDestroy()
	{
		FlagRunnerManager.Shutdown();
		ClearObjectiveFlags();
		if ((Object)(object)flagMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)flagMaterial);
		}
		if ((Object)(object)shieldRoot != (Object)null)
		{
			shieldRoot.SetActive(false);
			Object.Destroy((Object)(object)shieldRoot);
		}
		foreach (Texture2D uiTexture in uiTextures)
		{
			if ((Object)(object)uiTexture != (Object)null)
			{
				Object.Destroy((Object)(object)uiTexture);
			}
		}
		uiTextures.Clear();
		ready = false;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}

	private void BindFlags()
	{
		flagEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Flags", "Enabled", false, "Optional capture objectives in Attrition.");
		flagSuppression = ((BaseUnityPlugin)this).Config.Bind<bool>("Flags", "ReinforcementSuppression", true, "Trailing team receives replacements in proportion to flags owned.");
		flagDrain = ((BaseUnityPlugin)this).Config.Bind<bool>("Flags", "TicketDrain", false, "Lose one unreserved ticket per enemy surplus flag each interval.");
		flagRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Flags", "CaptureRadius", 10f, "Flag capture radius in game units.");
		flagCapture = ((BaseUnityPlugin)this).Config.Bind<float>("Flags", "CaptureSeconds", 15f, "Uncontested capture time.");
		flagDrainInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Flags", "DrainInterval", 5f, "Seconds between ticket drain events.");
		flagMinimum = ((BaseUnityPlugin)this).Config.Bind<int>("Flags", "MinimumAvailability", 0, "Minimum percentage of replacements allowed even when a team controls no flags (0% allows a complete block).");
		flagRunnerPercent = ((BaseUnityPlugin)this).Config.Bind<int>("Flags", "RunnerPercent", 50, "Percentage of eligible walkers assigned to objectives.");
	}

	public static bool TryGetNavigationObjective(Unit unit, out Vector3 position, out float stopRadius)
	{
		//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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0030: Invalid comparison between Unknown and I4
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: 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_00a3: 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)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		stopRadius = 0f;
		if (!FlagRoundActive || !Alive(unit) || ((int)unit.Team != 0 && (int)unit.Team != 1))
		{
			return false;
		}
		Plugin plugin = instance;
		int num = (((int)unit.Team == 0) ? 1 : 2);
		Vector3 val = (((Object)(object)unit.data.mainRig != (Object)null) ? unit.data.mainRig.position : ((Component)unit).transform.position);
		ObjectiveFlag objectiveFlag = null;
		float num2 = float.PositiveInfinity;
		foreach (ObjectiveFlag flag in plugin.flags)
		{
			if (flag.Owner != num)
			{
				Vector3 val2 = val - flag.Position;
				float num3 = val2.x * val2.x + val2.z * val2.z;
				if (num3 < num2)
				{
					objectiveFlag = flag;
					num2 = num3;
				}
			}
		}
		if (objectiveFlag == null)
		{
			return false;
		}
		position = objectiveFlag.Position;
		stopRadius = plugin.roundFlagRadius * 0.65f;
		return true;
	}

	internal static bool LocalFlagCombat(Vector3 position, bool alreadyFighting)
	{
		//IL_0051: 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_0058: 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_005f: 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)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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)
		Plugin plugin = instance;
		if (!FlagRoundActive)
		{
			return false;
		}
		float num = plugin.roundFlagRadius + (alreadyFighting ? 8f : 4f);
		foreach (ObjectiveFlag flag in plugin.flags)
		{
			if (flag.Contested || !(Time.time >= flag.CombatUntil))
			{
				Vector3 val = position - flag.Position;
				if (Mathf.Abs(val.y) <= plugin.roundFlagRadius + 2f && val.x * val.x + val.z * val.z <= num * num)
				{
					return true;
				}
			}
		}
		return false;
	}

	private void ResetFlagRound()
	{
		FlagRunnerManager.Reset();
		roundFlags = (roundSuppression = (roundDrain = false));
		redQuota.Reset();
		blueQuota.Reset();
		redOwned = (blueOwned = 0);
		lastFlagTick = -1f;
		nextFlagDrain = (nextFlagReport = 0f);
		foreach (ObjectiveFlag flag in flags)
		{
			flag.Owner = flag.InitialOwner;
			flag.Claim = 0;
			flag.Progress = 0f;
			flag.Contested = false;
			flag.CombatUntil = 0f;
			ColorFlag(flag);
		}
	}

	private void InitializeFlags()
	{
		ResetFlagRound();
		roundFlags = flagEnabled.Value && flags.Count > 0;
		roundSuppression = roundFlags && flagSuppression.Value;
		roundDrain = roundFlags && flagDrain.Value;
		roundFlagRadius = Clamp(flagRadius.Value, 1f, 50f, 10f);
		roundFlagCapture = Clamp(flagCapture.Value, 1f, 120f, 15f);
		roundDrainInterval = Clamp(flagDrainInterval.Value, 1f, 60f, 5f);
		roundMin = Mathf.Clamp(flagMinimum.Value, 0, 100);
		roundRunnerPercent = Mathf.Clamp(flagRunnerPercent.Value, 0, 100);
		foreach (ObjectiveFlag flag in flags)
		{
			if ((Object)(object)flag.Marker != (Object)null)
			{
				flag.Marker.SetActive(roundFlags);
			}
			UpdateRing(flag, roundFlagRadius);
		}
	}

	private void ClearObjectiveFlags()
	{
		foreach (ObjectiveFlag flag in flags)
		{
			if ((Object)(object)flag.Marker != (Object)null)
			{
				flag.Marker.SetActive(false);
				Object.Destroy((Object)(object)flag.Marker);
			}
		}
		flags.Clear();
		flagMessage = "Aim at ground and press Alt+G.";
	}

	private void UpdateFlagPlacement()
	{
		//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)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing re