Decompiled source of TABSUnlimited v1.0.0

TabsUnlimited.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using DM;
using HarmonyLib;
using InControl;
using Landfall.TABS;
using Landfall.TABS.AI.Components;
using Landfall.TABS.AI.Components.Modifiers;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.AI.Systems;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.TeamEdge;
using Landfall.TABS.UI;
using Landfall.TABS.UI.UIGroups.Attributes;
using Landfall.TABS.UI.Widgets.Fields;
using Landfall.TABS.UI.Widgets.List;
using Landfall.TABS.UI.WinConditions;
using Landfall.TABS.UnitEditor;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using Landfall.TABS_Input;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using StayCombatFix;
using TFBGames;
using TabsUnlimited.CustomVoices;
using TabsUnlimited.TeamLine;
using TabsUnlimited.WinConditions;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TabsUnlimited
{
	internal static class BattleStateHelper
	{
		private static int _checkFrame = -1;

		private static bool _cachedBattleActive;

		internal static bool IsBattleActive()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if (Time.frameCount == _checkFrame)
			{
				return _cachedBattleActive;
			}
			_checkFrame = Time.frameCount;
			GameStateManager service = ServiceLocator.GetService<GameStateManager>();
			_cachedBattleActive = service != null && (int)service.GameState == 1;
			return _cachedBattleActive;
		}

		internal static void InvalidateCache()
		{
			_checkFrame = -1;
		}
	}
	internal enum CustomEnemyTargetingMode
	{
		MostExpensive,
		LowestHealth,
		RangedMixedOnly
	}
	internal static class CustomEnemyTargetingSystem
	{
		private struct TeamEnemySnapshot
		{
			internal Entity Entity;

			internal Unit Unit;

			internal Vector3 Position;

			internal float Cost;

			internal float CurrentHealth;

			internal bool? IsRanged;

			internal float TargetPriority;

			internal float BeingTargetedBy;
		}

		private struct HunterState
		{
			internal Unit Unit;

			internal Entity Entity;

			internal Team Team;

			internal float AttackRange;

			internal Vector3 Position;

			internal CustomEnemyTargetingMode Mode;
		}

		private struct RangeScanResult
		{
			internal bool AnyInNear;

			internal bool AnyInApproach;

			internal bool FoundCurrentTarget;

			internal bool CurrentTargetAlive;

			internal float CurrentTargetSqrDistance;
		}

		private const float MinTargetPriority = 0.1f;

		private const float OvercrowdingFactor = 0.05f;

		private const int InitialSnapshotCapacity = 128;

		private const int InitialHunterCapacity = 32;

		private const int MaxCustomTargetingRetargetsPerFrame = 32;

		private static readonly List<TeamEnemySnapshot>[] TeamSnapshots = new List<TeamEnemySnapshot>[2]
		{
			new List<TeamEnemySnapshot>(128),
			new List<TeamEnemySnapshot>(128)
		};

		private static readonly List<HunterState> Hunters = new List<HunterState>(32);

		private static readonly Dictionary<Entity, float> LastRetargetTime = new Dictionary<Entity, float>();

		private static readonly Dictionary<Entity, TeamEnemySnapshot> SnapshotLookupByEntity = new Dictionary<Entity, TeamEnemySnapshot>();

		private static readonly Dictionary<UnitBlueprint, float> BlueprintCostCache = new Dictionary<UnitBlueprint, float>();

		private static float _lastSnapshotTime = -1f;

		private static int _lastSnapshotUnitCount = -1;

		private static int _retargetBudgetFrame = -1;

		private static int _retargetBudgetRemaining;

		private static readonly HashSet<Entity> IdleCustomHunterEntities = new HashSet<Entity>();

		private static readonly Dictionary<Entity, Unit> IdleCustomHunterUnits = new Dictionary<Entity, Unit>();

		internal static void InvalidateCaches()
		{
			_lastSnapshotTime = -1f;
			_lastSnapshotUnitCount = -1;
			TeamSnapshots[0].Clear();
			TeamSnapshots[1].Clear();
			SnapshotLookupByEntity.Clear();
			Hunters.Clear();
			LastRetargetTime.Clear();
			BlueprintCostCache.Clear();
			IdleCustomHunterEntities.Clear();
			IdleCustomHunterUnits.Clear();
			UnitBlueprintCombatHelper.InvalidateRangedCache();
		}

		internal static void PreUpdateBarrier_OnUpdate_Postfix()
		{
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected I4, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			if (!UnitEditorConfig.CustomTargetingTypesEnabled || !BattleStateHelper.IsBattleActive() || !EcsComponentHelper.IsAvailable)
			{
				return;
			}
			TeamSystem existingManager = EcsComponentHelper.GetExistingManager<TeamSystem>();
			if (existingManager == null)
			{
				return;
			}
			List<Unit> allUnits = existingManager.GetAllUnits();
			if (allUnits == null || allUnits.Count == 0)
			{
				return;
			}
			EntityManager entityManager = null;
			Entity entity;
			for (int i = 0; i < allUnits.Count && !EcsComponentHelper.TryGetEntityManager((Component)(object)allUnits[i], out entity, out entityManager); i++)
			{
			}
			if (!entityManager.IsCreated)
			{
				return;
			}
			IdleCustomHunterEntities.Clear();
			IdleCustomHunterUnits.Clear();
			CollectHunters(allUnits, entityManager);
			if (Hunters.Count == 0)
			{
				return;
			}
			EnsureSnapshotsFresh(existingManager, entityManager, allUnits.Count);
			float time = Time.time;
			float retargetInterval = 0.25f;
			EnsureRetargetBudget();
			for (int j = 0; j < Hunters.Count; j++)
			{
				HunterState hunter = Hunters[j];
				if (FleeDistanceInterop.IsAiEnabled && entityManager.HasComponent<FleeDistance>(hunter.Entity) && (FleeDistanceInterop.IsFleeManaged(hunter.Entity) || FleeDistanceInterop.ShouldFlee(entityManager, hunter.Entity)))
				{
					continue;
				}
				int num = (int)TeamUtlity.GetOtherTeam(hunter.Team);
				List<TeamEnemySnapshot> list = TeamSnapshots[num];
				if (list.Count == 0)
				{
					ForceIdleCustomHunter(entityManager, hunter);
					continue;
				}
				float inRangeCutoffSq = ComputeInRangeCutoffSq(hunter);
				float farMaxSq = ComputeFarMaxSq(hunter);
				Entity val = Entity.Null;
				if (EcsComponentHelper.TryGetComponentData<HasTargetTag>(entityManager, hunter.Entity, out HasTargetTag data))
				{
					val = data.Target;
				}
				RangeScanResult rangeScan = ScanEnemyRanges(list, hunter.Position, inRangeCutoffSq, farMaxSq, val);
				if (!rangeScan.AnyInNear && !rangeScan.AnyInApproach)
				{
					ForceIdleCustomHunter(entityManager, hunter);
					LastRetargetTime[hunter.Entity] = time;
				}
				else
				{
					if (ShouldSkipRetarget(hunter.Entity, val, rangeScan, inRangeCutoffSq, farMaxSq, time, retargetInterval))
					{
						continue;
					}
					bool flag = IsUrgentRetarget(val, rangeScan, inRangeCutoffSq, farMaxSq);
					if (!flag && _retargetBudgetRemaining <= 0)
					{
						continue;
					}
					if (!TryPickTargetSinglePass(hunter.Mode, hunter.Position, hunter.AttackRange, inRangeCutoffSq, farMaxSq, list, rangeScan.AnyInNear, out var targetEntity, out var usedNearMode))
					{
						ForceIdleCustomHunter(entityManager, hunter);
						continue;
					}
					if (!flag)
					{
						_retargetBudgetRemaining--;
					}
					if (targetEntity == val)
					{
						LastRetargetTime[hunter.Entity] = time;
						continue;
					}
					ApplyTarget(entityManager, hunter.Entity, targetEntity, usedNearMode);
					LastRetargetTime[hunter.Entity] = time;
				}
			}
		}

		internal static void UnitECSToMonoSyncSystem_OnUpdate_Postfix()
		{
			if (!UnitEditorConfig.CustomTargetingTypesEnabled || !BattleStateHelper.IsBattleActive() || IdleCustomHunterUnits.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<Entity, Unit> idleCustomHunterUnit in IdleCustomHunterUnits)
			{
				Unit value = idleCustomHunterUnit.Value;
				if (!((Object)(object)value == (Object)null) && !value.dead && !((Object)(object)value.api == (Object)null))
				{
					value.api.SetMovementSpeed(0f, true);
				}
			}
		}

		private static float ComputeInRangeCutoffSq(HunterState hunter)
		{
			float item = GetRangeProfile(hunter.Mode, hunter.AttackRange).nearFraction;
			float num = hunter.AttackRange * item;
			return num * num;
		}

		private static float ComputeFarMaxSq(HunterState hunter)
		{
			float item = GetRangeProfile(hunter.Mode, hunter.AttackRange).approachMultiplier;
			float num = hunter.AttackRange * item;
			return num * num;
		}

		private static RangeScanResult ScanEnemyRanges(List<TeamEnemySnapshot> enemies, Vector3 hunterPosition, float inRangeCutoffSq, float farMaxSq, Entity currentTarget)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_008a: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			RangeScanResult rangeScanResult = default(RangeScanResult);
			rangeScanResult.CurrentTargetSqrDistance = float.MaxValue;
			RangeScanResult result = rangeScanResult;
			Vector3 val;
			if (currentTarget != Entity.Null && SnapshotLookupByEntity.TryGetValue(currentTarget, out var value))
			{
				result.FoundCurrentTarget = true;
				result.CurrentTargetAlive = (Object)(object)value.Unit != (Object)null && !value.Unit.dead;
				val = value.Position - hunterPosition;
				result.CurrentTargetSqrDistance = ((Vector3)(ref val)).sqrMagnitude;
			}
			for (int i = 0; i < enemies.Count; i++)
			{
				val = enemies[i].Position - hunterPosition;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (sqrMagnitude <= inRangeCutoffSq)
				{
					result.AnyInNear = true;
				}
				if (sqrMagnitude <= farMaxSq)
				{
					result.AnyInApproach = true;
				}
				if (result.AnyInNear && result.AnyInApproach)
				{
					break;
				}
			}
			return result;
		}

		private static bool ShouldSkipRetarget(Entity hunterEntity, Entity currentTarget, RangeScanResult rangeScan, float inRangeCutoffSq, float farMaxSq, float now, float retargetInterval)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (currentTarget == Entity.Null)
			{
				return false;
			}
			if (!rangeScan.FoundCurrentTarget || !rangeScan.CurrentTargetAlive)
			{
				return false;
			}
			if (rangeScan.AnyInNear && rangeScan.CurrentTargetSqrDistance > inRangeCutoffSq)
			{
				return false;
			}
			if (!rangeScan.AnyInNear && rangeScan.AnyInApproach && rangeScan.CurrentTargetSqrDistance > farMaxSq)
			{
				return false;
			}
			if (retargetInterval <= 0f || !LastRetargetTime.TryGetValue(hunterEntity, out var value) || now - value >= retargetInterval)
			{
				return false;
			}
			if (!rangeScan.AnyInNear && !rangeScan.AnyInApproach && rangeScan.CurrentTargetSqrDistance <= farMaxSq)
			{
				return false;
			}
			return true;
		}

		private static bool IsUrgentRetarget(Entity currentTarget, RangeScanResult rangeScan, float inRangeCutoffSq, float farMaxSq)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (currentTarget == Entity.Null)
			{
				return true;
			}
			if (!rangeScan.FoundCurrentTarget || !rangeScan.CurrentTargetAlive)
			{
				return true;
			}
			if (rangeScan.AnyInNear && rangeScan.CurrentTargetSqrDistance > inRangeCutoffSq)
			{
				return true;
			}
			if (!rangeScan.AnyInNear && rangeScan.AnyInApproach && rangeScan.CurrentTargetSqrDistance > farMaxSq)
			{
				return true;
			}
			return false;
		}

		private static void ForceIdleCustomHunter(EntityManager entityManager, HunterState hunter)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001b: 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_0042: 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_0036: 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_0050: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			entityManager.SetComponentData<HasTargetTag>(hunter.Entity, new HasTargetTag
			{
				Target = Entity.Null
			});
			if (entityManager.HasComponent<TargetData>(hunter.Entity))
			{
				entityManager.SetComponentData<TargetData>(hunter.Entity, TargetData.Null);
			}
			if (entityManager.HasComponent<Velocity>(hunter.Entity))
			{
				entityManager.SetComponentData<Velocity>(hunter.Entity, new Velocity
				{
					Value = float3.zero
				});
			}
			IdleCustomHunterEntities.Add(hunter.Entity);
			if ((Object)(object)hunter.Unit != (Object)null)
			{
				IdleCustomHunterUnits[hunter.Entity] = hunter.Unit;
			}
		}

		private static void EnsureRetargetBudget()
		{
			if (Time.frameCount != _retargetBudgetFrame)
			{
				_retargetBudgetFrame = Time.frameCount;
				_retargetBudgetRemaining = 32;
			}
		}

		private static void EnsureSnapshotsFresh(TeamSystem teamSystem, EntityManager entityManager, int liveUnitCount)
		{
			float time = Time.time;
			float num = 0.25f;
			int num2 = TeamSnapshots[0].Count + TeamSnapshots[1].Count;
			if (!(_lastSnapshotTime >= 0f) || !(time - _lastSnapshotTime < num) || _lastSnapshotUnitCount != liveUnitCount || num2 <= 0)
			{
				BuildTeamSnapshots(teamSystem, entityManager);
				RebuildSnapshotLookup();
				_lastSnapshotTime = time;
				_lastSnapshotUnitCount = liveUnitCount;
			}
		}

		private static void RebuildSnapshotLookup()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			SnapshotLookupByEntity.Clear();
			for (int i = 0; i < TeamSnapshots.Length; i++)
			{
				List<TeamEnemySnapshot> list = TeamSnapshots[i];
				for (int j = 0; j < list.Count; j++)
				{
					SnapshotLookupByEntity[list[j].Entity] = list[j];
				}
			}
		}

		private static void BuildTeamSnapshots(TeamSystem teamSystem, EntityManager entityManager)
		{
			TeamSnapshots[0].Clear();
			TeamSnapshots[1].Clear();
			AddTeamSnapshot(teamSystem, entityManager, (Team)0, TeamSnapshots[0]);
			AddTeamSnapshot(teamSystem, entityManager, (Team)1, TeamSnapshots[1]);
		}

		private static void AddTeamSnapshot(TeamSystem teamSystem, EntityManager entityManager, Team team, List<TeamEnemySnapshot> snapshot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00b8: 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_00c5: 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)
			List<Unit> teamUnits = teamSystem.GetTeamUnits(team);
			if (teamUnits == null)
			{
				return;
			}
			for (int i = 0; i < teamUnits.Count; i++)
			{
				Unit val = teamUnits[i];
				if (!((Object)(object)val == (Object)null) && !val.dead && EcsComponentHelper.TryGetEntityManager((Component)(object)val, out var entity, out var _))
				{
					float targetPriority = 0.1f;
					if (EcsComponentHelper.TryGetComponentData<TargetPriority>(entityManager, entity, out TargetPriority data))
					{
						targetPriority = Mathf.Max(data.Value, 0.1f);
					}
					float beingTargetedBy = 0f;
					if (EcsComponentHelper.TryGetComponentData<BeingTargetedBy>(entityManager, entity, out BeingTargetedBy data2))
					{
						beingTargetedBy = data2.Value;
					}
					float currentHealth = float.MaxValue;
					if (EcsComponentHelper.TryGetComponentData<Health>(entityManager, entity, out Health data3))
					{
						currentHealth = data3.CurrentHealth;
					}
					snapshot.Add(new TeamEnemySnapshot
					{
						Entity = entity,
						Unit = val,
						Position = GetUnitPosition(val),
						Cost = GetUnitCost(entityManager, entity, val),
						CurrentHealth = currentHealth,
						IsRanged = UnitBlueprintCombatHelper.ClassifyIsRanged(val.unitBlueprint),
						TargetPriority = targetPriority,
						BeingTargetedBy = beingTargetedBy
					});
				}
			}
		}

		private static void CollectHunters(List<Unit> allUnits, EntityManager entityManager)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			Hunters.Clear();
			if (allUnits == null)
			{
				return;
			}
			for (int i = 0; i < allUnits.Count; i++)
			{
				Unit val = allUnits[i];
				if (!((Object)(object)val == (Object)null) && !val.dead && EcsComponentHelper.TryGetEntityManager((Component)(object)val, out var entity, out var _) && TryGetTargetingMode(entityManager, entity, out var mode))
				{
					Hunters.Add(new HunterState
					{
						Unit = val,
						Entity = entity,
						Team = val.Team,
						AttackRange = GetAttackRange(val, entityManager, entity),
						Position = GetUnitPosition(val),
						Mode = mode
					});
				}
			}
		}

		private static bool TryGetTargetingMode(EntityManager entityManager, Entity entity, out CustomEnemyTargetingMode mode)
		{
			//IL_0001: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			if (entityManager.HasComponent<EnemyHighestPriceTargeting>(entity))
			{
				mode = CustomEnemyTargetingMode.MostExpensive;
				return true;
			}
			if (entityManager.HasComponent<EnemyLowestHealthTargeting>(entity))
			{
				mode = CustomEnemyTargetingMode.LowestHealth;
				return true;
			}
			if (entityManager.HasComponent<EnemyRangedMixedTargeting>(entity))
			{
				mode = CustomEnemyTargetingMode.RangedMixedOnly;
				return true;
			}
			mode = CustomEnemyTargetingMode.MostExpensive;
			return false;
		}

		private static bool TryPickTargetSinglePass(CustomEnemyTargetingMode mode, Vector3 hunterPosition, float attackRange, float inRangeCutoffSq, float farMaxSq, List<TeamEnemySnapshot> enemies, bool anyInNear, out Entity targetEntity, out bool usedNearMode)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001d: 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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_008f: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: 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_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			targetEntity = Entity.Null;
			usedNearMode = anyInNear;
			Entity val = Entity.Null;
			float num = float.MinValue;
			Entity val2 = Entity.Null;
			float num2 = float.MinValue;
			Entity bestEntity = Entity.Null;
			float bestCost = float.MinValue;
			float bestSqrDistance = float.MaxValue;
			Entity bestEntity2 = Entity.Null;
			float bestHealth = float.MaxValue;
			float bestSqrDistance2 = float.MaxValue;
			Entity val3 = Entity.Null;
			float num3 = float.MaxValue;
			Entity val4 = Entity.Null;
			float num4 = float.MaxValue;
			for (int i = 0; i < enemies.Count; i++)
			{
				TeamEnemySnapshot candidate = enemies[i];
				Vector3 val5 = candidate.Position - hunterPosition;
				float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
				if (sqrMagnitude <= inRangeCutoffSq)
				{
					float num5 = (0f - Mathf.Sqrt(sqrMagnitude)) / candidate.TargetPriority - candidate.BeingTargetedBy * attackRange * 0.05f;
					if (num5 > num)
					{
						num = num5;
						val = candidate.Entity;
					}
					if (candidate.IsRanged == false && num5 > num2)
					{
						num2 = num5;
						val2 = candidate.Entity;
					}
				}
				if (sqrMagnitude <= farMaxSq)
				{
					ConsiderHighestCost(candidate, sqrMagnitude, ref bestEntity, ref bestCost, ref bestSqrDistance);
					ConsiderLowestHealth(candidate, sqrMagnitude, ref bestEntity2, ref bestHealth, ref bestSqrDistance2);
					if (candidate.IsRanged != false && sqrMagnitude < num3)
					{
						num3 = sqrMagnitude;
						val3 = candidate.Entity;
					}
					if (sqrMagnitude < num4)
					{
						num4 = sqrMagnitude;
						val4 = candidate.Entity;
					}
				}
			}
			if (usedNearMode)
			{
				if (mode == CustomEnemyTargetingMode.RangedMixedOnly && val2 != Entity.Null)
				{
					targetEntity = val2;
				}
				else
				{
					targetEntity = val;
				}
				return targetEntity != Entity.Null;
			}
			switch (mode)
			{
			case CustomEnemyTargetingMode.MostExpensive:
				if (bestEntity != Entity.Null)
				{
					targetEntity = bestEntity;
					return true;
				}
				return false;
			case CustomEnemyTargetingMode.LowestHealth:
				if (bestEntity2 != Entity.Null)
				{
					targetEntity = bestEntity2;
					return true;
				}
				return false;
			case CustomEnemyTargetingMode.RangedMixedOnly:
				if (val3 != Entity.Null)
				{
					targetEntity = val3;
					return true;
				}
				if (val4 != Entity.Null)
				{
					targetEntity = val4;
					return true;
				}
				return false;
			default:
				return false;
			}
		}

		private static void ConsiderHighestCost(TeamEnemySnapshot candidate, float sqrDistance, ref Entity bestEntity, ref float bestCost, ref float bestSqrDistance)
		{
			//IL_002e: 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)
			if (!(candidate.Cost < bestCost) && (!Mathf.Approximately(candidate.Cost, bestCost) || !(sqrDistance >= bestSqrDistance)))
			{
				bestCost = candidate.Cost;
				bestSqrDistance = sqrDistance;
				bestEntity = candidate.Entity;
			}
		}

		private static void ConsiderLowestHealth(TeamEnemySnapshot candidate, float sqrDistance, ref Entity bestEntity, ref float bestHealth, ref float bestSqrDistance)
		{
			//IL_002e: 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)
			if (!(candidate.CurrentHealth > bestHealth) && (!Mathf.Approximately(candidate.CurrentHealth, bestHealth) || !(sqrDistance >= bestSqrDistance)))
			{
				bestHealth = candidate.CurrentHealth;
				bestSqrDistance = sqrDistance;
				bestEntity = candidate.Entity;
			}
		}

		private static void ApplyTarget(EntityManager entityManager, Entity hunterEntity, Entity targetEntity, bool usedNearMode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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)
			//IL_001c: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			entityManager.SetComponentData<HasTargetTag>(hunterEntity, new HasTargetTag
			{
				Target = targetEntity
			});
			entityManager.SetComponentData<IsTarget>(targetEntity, new IsTarget
			{
				Targetee = hunterEntity
			});
			entityManager.SetComponentData<AttackThickness>(hunterEntity, new AttackThickness
			{
				Value = 0f
			});
			if (usedNearMode && EcsComponentHelper.TryGetComponentData<BeingTargetedBy>(entityManager, targetEntity, out BeingTargetedBy data))
			{
				data.Value += 1f;
				entityManager.SetComponentData<BeingTargetedBy>(targetEntity, data);
			}
		}

		private static (float nearFraction, float approachMultiplier) GetRangeProfile(CustomEnemyTargetingMode mode, float attackRange)
		{
			bool flag = attackRange <= 15f;
			if (mode == CustomEnemyTargetingMode.RangedMixedOnly)
			{
				if (!flag)
				{
					return (0.25f, 1.5f);
				}
				return (0.5f, 2.5f);
			}
			if (!flag)
			{
				return (0.5f, 1.5f);
			}
			return (0.75f, 2.5f);
		}

		private static float GetAttackRange(Unit hunter, EntityManager entityManager, Entity hunterEntity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (EcsComponentHelper.TryGetComponentData<Range>(entityManager, hunterEntity, out Range data))
			{
				return data.AttackRange;
			}
			if (!((Object)(object)hunter != (Object)null))
			{
				return 1f;
			}
			return hunter.m_AttackDistance;
		}

		private static float GetUnitCost(EntityManager entityManager, Entity entity, Unit unit)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (EcsComponentHelper.TryGetComponentData<UnitCost>(entityManager, entity, out UnitCost data))
			{
				return data.Value;
			}
			UnitBlueprint val = unit?.unitBlueprint;
			if ((Object)(object)val == (Object)null)
			{
				return 0f;
			}
			if (BlueprintCostCache.TryGetValue(val, out var value))
			{
				return value;
			}
			value = val.GetUnitCost(true);
			BlueprintCostCache[val] = value;
			return value;
		}

		private static Vector3 GetUnitPosition(Unit unit)
		{
			//IL_002b: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)unit?.data?.mainRig != (Object)null)
			{
				return unit.data.mainRig.position;
			}
			if (!((Object)(object)unit != (Object)null))
			{
				return Vector3.zero;
			}
			return ((Component)unit).transform.position;
		}
	}
	internal enum CustomVoiceOverlayView
	{
		Hub,
		OggEditor
	}
	internal static class CustomVoiceEditorOverlay
	{
		private sealed class OggRowUi
		{
			internal string FileName;

			internal Button NormalButton;

			internal Button DeathButton;

			internal Text NormalLabel;

			internal Text DeathLabel;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__UpdateSummary;

			public static UnityAction <1>__ShowHub;

			public static UnityAction <2>__SavePack;

			public static UnityAction <3>__DeleteEditingPack;

			public static UnityAction <4>__ShowOggEditorNew;

			public static UnityAction <5>__Close;

			public static UnityAction <6>__OpenSourcesFolder;
		}

		private const float RowHeight = 48f;

		private const float HubHeaderHeight = 148f;

		private const float EditorHeaderHeight = 200f;

		private const float FooterHeight = 52f;

		private static readonly Color RowEven = new Color(0.11f, 0.11f, 0.11f, 0.92f);

		private static readonly Color RowOdd = new Color(0.145f, 0.145f, 0.145f, 0.92f);

		private static readonly Color ToggleOn = new Color(0.2f, 0.48f, 0.28f, 0.98f);

		private static readonly Color ToggleOff = new Color(0.18f, 0.18f, 0.18f, 0.96f);

		private static GameObject _canvasRoot;

		private static GameObject _panel;

		private static RectTransform _headerRect;

		private static RectTransform _scrollHostRect;

		private static Text _titleText;

		private static Text _instructionsText;

		private static Text _summaryText;

		private static InputField _searchField;

		private static RectTransform _searchRect;

		private static GameObject _packNameContainer;

		private static InputField _packNameField;

		private static Button _openFolderButton;

		private static Transform _listContent;

		private static ScrollRect _scrollRect;

		private static GameObject _footer;

		private static Button _footerPrimary;

		private static Button _footerSecondary;

		private static Button _footerDelete;

		private static Text _footerPrimaryLabel;

		private static Text _footerSecondaryLabel;

		private static CustomVoiceOverlayView _view = CustomVoiceOverlayView.Hub;

		private static string _search = string.Empty;

		private static string _editingPackId;

		private static readonly Dictionary<string, bool> NormalByFile = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, bool> DeathByFile = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);

		private static readonly List<OggRowUi> OggRows = new List<OggRowUi>();

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_panel != (Object)null)
				{
					return _panel.activeSelf;
				}
				return false;
			}
		}

		internal static void Open()
		{
			if (UnitEditorConfig.CustomVoicesEnabled)
			{
				CustomVoiceStore.LoadAll();
				EnsureBuilt();
				_search = string.Empty;
				_editingPackId = null;
				if ((Object)(object)_searchField != (Object)null)
				{
					_searchField.text = string.Empty;
				}
				_canvasRoot.SetActive(true);
				_panel.SetActive(true);
				UpdateInstructions();
				UpdateTabTitle();
				ShowHub();
				CustomVoiceOggCatalog.BeginRefresh(UpdateSummary);
			}
		}

		internal static void Close()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				_panel.SetActive(false);
			}
			if ((Object)(object)_canvasRoot != (Object)null)
			{
				_canvasRoot.SetActive(false);
			}
			_editingPackId = null;
			NormalByFile.Clear();
			DeathByFile.Clear();
		}

		private static void ShowHub()
		{
			_view = CustomVoiceOverlayView.Hub;
			_editingPackId = null;
			NormalByFile.Clear();
			DeathByFile.Clear();
			RefreshUi();
		}

		private static void ShowOggEditorNew()
		{
			_view = CustomVoiceOverlayView.OggEditor;
			_editingPackId = null;
			NormalByFile.Clear();
			DeathByFile.Clear();
			if ((Object)(object)_packNameField != (Object)null)
			{
				_packNameField.text = string.Empty;
			}
			BeginCatalogRefreshForEditor();
		}

		private static void ShowOggEditorForEdit(CustomVoicePack pack)
		{
			if (pack == null)
			{
				return;
			}
			_view = CustomVoiceOverlayView.OggEditor;
			_editingPackId = pack.id;
			NormalByFile.Clear();
			DeathByFile.Clear();
			if (pack.vocalFiles != null)
			{
				for (int i = 0; i < pack.vocalFiles.Count; i++)
				{
					NormalByFile[pack.vocalFiles[i]] = true;
				}
			}
			if (pack.deathFiles != null)
			{
				for (int j = 0; j < pack.deathFiles.Count; j++)
				{
					DeathByFile[pack.deathFiles[j]] = true;
				}
			}
			if ((Object)(object)_packNameField != (Object)null)
			{
				_packNameField.text = pack.name ?? "Custom Voice";
			}
			BeginCatalogRefreshForEditor();
		}

		private static void BeginCatalogRefreshForEditor()
		{
			UpdateHeaderLayout();
			UpdateInstructions();
			ConfigureFooter();
			ClearListRows();
			UpdateSummary();
			CustomVoiceOggCatalog.BeginRefresh(delegate
			{
				PruneIneligibleSelections();
				RefreshUi();
			});
		}

		private static void PruneIneligibleSelections()
		{
			foreach (string item in NormalByFile.Keys.ToList())
			{
				if (!CustomVoiceOggCatalog.IsFileEligible(item))
				{
					NormalByFile[item] = false;
				}
			}
			foreach (string item2 in DeathByFile.Keys.ToList())
			{
				if (!CustomVoiceOggCatalog.IsFileEligible(item2))
				{
					DeathByFile[item2] = false;
				}
			}
		}

		private static void RefreshUi()
		{
			UpdateHeaderLayout();
			UpdateInstructions();
			ConfigureFooter();
			ClearListRows();
			UpdateSummary();
			if (_view == CustomVoiceOverlayView.Hub)
			{
				BuildHubRows();
			}
			else
			{
				BuildOggRows();
			}
			if ((Object)(object)_scrollRect != (Object)null)
			{
				_scrollRect.verticalNormalizedPosition = 1f;
			}
		}

		private static void UpdateHeaderLayout()
		{
			//IL_0031: 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_0144: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_00c5: 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_00f7: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _view == CustomVoiceOverlayView.OggEditor;
			float num = (flag ? 200f : 148f);
			if ((Object)(object)_headerRect != (Object)null)
			{
				_headerRect.sizeDelta = new Vector2(0f, num);
			}
			if ((Object)(object)_scrollHostRect != (Object)null)
			{
				_scrollHostRect.offsetMax = new Vector2(-8f, 0f - (num + 4f));
			}
			if ((Object)(object)_packNameContainer != (Object)null)
			{
				_packNameContainer.SetActive(flag);
			}
			UpdateTabTitle();
			UpdateInstructions();
			if ((Object)(object)_openFolderButton != (Object)null)
			{
				((Component)_openFolderButton).gameObject.SetActive(flag);
			}
			if ((Object)(object)_searchRect != (Object)null)
			{
				if (flag)
				{
					_searchRect.anchorMin = new Vector2(0f, 0f);
					_searchRect.anchorMax = new Vector2(0f, 0f);
					_searchRect.pivot = new Vector2(0f, 0f);
					_searchRect.anchoredPosition = new Vector2(16f, 12f);
					_searchRect.sizeDelta = new Vector2(360f, 32f);
				}
				else
				{
					_searchRect.anchorMin = new Vector2(0f, 0f);
					_searchRect.anchorMax = new Vector2(0f, 0f);
					_searchRect.pivot = new Vector2(0f, 0f);
					_searchRect.anchoredPosition = new Vector2(16f, 12f);
					_searchRect.sizeDelta = new Vector2(360f, 32f);
				}
			}
			if ((Object)(object)_instructionsText != (Object)null)
			{
				RectTransform component = ((Component)_instructionsText).GetComponent<RectTransform>();
				if (flag)
				{
					component.offsetMin = new Vector2(16f, -108f);
					component.offsetMax = new Vector2(-120f, -32f);
				}
				else
				{
					component.offsetMin = new Vector2(16f, -88f);
					component.offsetMax = new Vector2(-16f, -32f);
				}
			}
			if ((Object)(object)_titleText != (Object)null)
			{
				RectTransform component2 = ((Component)_titleText).GetComponent<RectTransform>();
				component2.offsetMin = new Vector2(16f, -8f);
				component2.offsetMax = new Vector2(-120f, -28f);
			}
			if ((Object)(object)_packNameContainer != (Object)null && flag)
			{
				RectTransform component3 = _packNameContainer.GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(0f, 1f);
				component3.anchorMax = new Vector2(0f, 1f);
				component3.pivot = new Vector2(0f, 1f);
				component3.anchoredPosition = new Vector2(16f, -114f);
				component3.sizeDelta = new Vector2(280f, 24f);
			}
			if ((Object)(object)_summaryText != (Object)null)
			{
				RectTransform component4 = ((Component)_summaryText).GetComponent<RectTransform>();
				component4.anchorMin = new Vector2(0f, 0f);
				component4.anchorMax = new Vector2(0f, 0f);
				component4.pivot = new Vector2(0f, 0f);
				component4.anchoredPosition = new Vector2(392f, 12f);
				component4.sizeDelta = new Vector2(flag ? 280f : 360f, 32f);
				_summaryText.alignment = (TextAnchor)3;
				((Component)_summaryText).gameObject.SetActive(true);
			}
		}

		private static void UpdateTabTitle()
		{
			if (!((Object)(object)_titleText == (Object)null))
			{
				if (_view == CustomVoiceOverlayView.Hub)
				{
					_titleText.text = "CUSTOM VOICES";
				}
				else if (!string.IsNullOrEmpty(_editingPackId))
				{
					_titleText.text = "EDIT VOICE";
				}
				else
				{
					_titleText.text = "MAKE NEW VOICE";
				}
			}
		}

		private static void UpdateInstructions()
		{
			if (!((Object)(object)_instructionsText == (Object)null))
			{
				if (_view == CustomVoiceOverlayView.Hub)
				{
					_instructionsText.text = "Make New Voice to create a pack. Equip applies a pack to your unit; Edit changes its sounds. Voice files live in CustomContent/voices — use Open File in the editor to add .ogg files.";
				}
				else
				{
					_instructionsText.text = "Type a name, then assign sounds below. Only .ogg files up to " + 7f.ToString("0.#") + " seconds appear here. Open File opens CustomContent/voices — copy .ogg files there, then press Back and re-enter to refresh. Delete removes a file from disk and all packs. Preview plays a file. Pick at least one Normal and one Death line before Save.";
				}
			}
		}

		private static void ConfigureFooter()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			if ((Object)(object)_footer == (Object)null)
			{
				return;
			}
			if (_view == CustomVoiceOverlayView.Hub)
			{
				_footer.SetActive(false);
				return;
			}
			_footer.SetActive(true);
			((Component)_footerSecondary).gameObject.SetActive(true);
			((Component)_footerPrimary).gameObject.SetActive(true);
			_footerSecondaryLabel.text = "Back";
			_footerPrimaryLabel.text = "Save";
			Button footerSecondary = _footerSecondary;
			object obj = <>O.<1>__ShowHub;
			if (obj == null)
			{
				UnityAction val = ShowHub;
				<>O.<1>__ShowHub = val;
				obj = (object)val;
			}
			UnitEditorUiText.ReplaceButtonClick(footerSecondary, (UnityAction)obj);
			Button footerPrimary = _footerPrimary;
			object obj2 = <>O.<2>__SavePack;
			if (obj2 == null)
			{
				UnityAction val2 = SavePack;
				<>O.<2>__SavePack = val2;
				obj2 = (object)val2;
			}
			UnitEditorUiText.ReplaceButtonClick(footerPrimary, (UnityAction)obj2);
			if (!((Object)(object)_footerDelete != (Object)null))
			{
				return;
			}
			bool flag = !string.IsNullOrEmpty(_editingPackId);
			((Component)_footerDelete).gameObject.SetActive(flag);
			if (flag)
			{
				Button footerDelete = _footerDelete;
				object obj3 = <>O.<3>__DeleteEditingPack;
				if (obj3 == null)
				{
					UnityAction val3 = DeleteEditingPack;
					<>O.<3>__DeleteEditingPack = val3;
					obj3 = (object)val3;
				}
				UnitEditorUiText.ReplaceButtonClick(footerDelete, (UnityAction)obj3);
			}
		}

		private static void BuildHubRows()
		{
			if (MatchesSearch("Make New Voice"))
			{
				CreateMakeNewHubRow();
			}
			IReadOnlyList<CustomVoicePack> allPacks = CustomVoiceStore.AllPacks;
			for (int i = 0; i < allPacks.Count; i++)
			{
				CustomVoicePack customVoicePack = allPacks[i];
				if (customVoicePack != null && MatchesSearch(customVoicePack.name))
				{
					CreatePackHubRow(customVoicePack);
				}
			}
		}

		private static void CreateMakeNewHubRow()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			GameObject obj = CreateRowShell("MakeNew".GetHashCode());
			Image component = obj.GetComponent<Image>();
			((Graphic)component).color = new Color(0.16f, 0.32f, 0.18f, 0.95f);
			CreateRowLabel(obj.transform, "Make New Voice", 16f, new Vector2(12f, 0f), new Vector2(-12f, 0f));
			Button obj2 = obj.AddComponent<Button>();
			((Selectable)obj2).targetGraphic = (Graphic)(object)component;
			object obj3 = <>O.<4>__ShowOggEditorNew;
			if (obj3 == null)
			{
				UnityAction val = ShowOggEditorNew;
				<>O.<4>__ShowOggEditorNew = val;
				obj3 = (object)val;
			}
			UnitEditorUiText.ReplaceButtonClick(obj2, (UnityAction)obj3);
		}

		private static void CreatePackHubRow(CustomVoicePack pack)
		{
			//IL_001d: 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_0051: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0149: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			GameObject val = CreateRowShell(pack.id.GetHashCode());
			((Graphic)val.GetComponent<Image>()).color = RowEven;
			CreateRowLabel(val.transform, pack.name, 16f, new Vector2(56f, 0f), new Vector2(-260f, 0f));
			if (CustomVoiceRegistry.TryGetBundle(pack.id, out var bundle))
			{
				object obj;
				if (bundle == null)
				{
					obj = null;
				}
				else
				{
					DatabaseEntity entity = bundle.Entity;
					obj = ((entity != null) ? entity.SpriteIcon : null);
				}
				if ((Object)obj != (Object)null)
				{
					CreateRowIcon(val.transform, bundle.Entity.SpriteIcon);
				}
			}
			CustomVoicePack captured = pack;
			Button button = CreateSmallButton(val.transform, "Edit", new Vector2(-176f, 0f), new Vector2(72f, 32f), (TextAnchor)5);
			Button button2 = CreateSmallButton(val.transform, "Equip", new Vector2(-96f, 0f), new Vector2(72f, 32f), (TextAnchor)5);
			Button button3 = CreateSmallButton(val.transform, "Delete", new Vector2(-16f, 0f), new Vector2(72f, 32f), (TextAnchor)5);
			UnitEditorUiText.ReplaceButtonClick(button, (UnityAction)delegate
			{
				ShowOggEditorForEdit(captured);
			});
			UnitEditorUiText.ReplaceButtonClick(button2, (UnityAction)delegate
			{
				EquipPack(captured);
			});
			UnitEditorUiText.ReplaceButtonClick(button3, (UnityAction)delegate
			{
				DeletePack(captured);
			});
		}

		private static void BuildOggRows()
		{
			OggRows.Clear();
			IReadOnlyList<CustomVoiceOggEntry> entriesSnapshot = CustomVoiceOggCatalog.EntriesSnapshot;
			for (int i = 0; i < entriesSnapshot.Count; i++)
			{
				CustomVoiceOggEntry customVoiceOggEntry = entriesSnapshot[i];
				if (customVoiceOggEntry != null && (MatchesSearch(customVoiceOggEntry.DisplayName) || MatchesSearch(customVoiceOggEntry.FileName)))
				{
					CreateOggRow(customVoiceOggEntry, i);
				}
			}
			RefreshAllOggToggleStates();
		}

		private static void CreateOggRow(CustomVoiceOggEntry entry, int index)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0156: Expected O, but got Unknown
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			GameObject obj = CreateRowShell(entry.FileName.GetHashCode());
			((Graphic)obj.GetComponent<Image>()).color = ((index % 2 == 0) ? RowEven : RowOdd);
			CreateRowLabel(obj.transform, entry.DisplayName, 14f, new Vector2(96f, 0f), new Vector2(-280f, 0f));
			UnitEditorUiText.ReplaceButtonClick(CreateSmallButton(obj.transform, "Preview", new Vector2(8f, 0f), new Vector2(72f, 32f), (TextAnchor)3), (UnityAction)delegate
			{
				CustomVoicePreview.PlayFile(entry.FileName);
			});
			Button val = CreateSmallButton(obj.transform, "Normal", new Vector2(-248f, 0f), new Vector2(72f, 32f), (TextAnchor)5);
			Button val2 = CreateSmallButton(obj.transform, "Death", new Vector2(-168f, 0f), new Vector2(72f, 32f), (TextAnchor)5);
			UnitEditorUiText.ReplaceButtonClick(CreateSmallButton(obj.transform, "Delete", new Vector2(-88f, 0f), new Vector2(72f, 32f), (TextAnchor)5), (UnityAction)delegate
			{
				DeleteSourceFile(entry.FileName);
			});
			OggRowUi rowUi = new OggRowUi
			{
				FileName = entry.FileName,
				NormalButton = val,
				DeathButton = val2,
				NormalLabel = ((Component)val).GetComponentInChildren<Text>(),
				DeathLabel = ((Component)val2).GetComponentInChildren<Text>()
			};
			if (!NormalByFile.ContainsKey(entry.FileName))
			{
				NormalByFile[entry.FileName] = false;
			}
			if (!DeathByFile.ContainsKey(entry.FileName))
			{
				DeathByFile[entry.FileName] = false;
			}
			UnitEditorUiText.ReplaceButtonClick(val, (UnityAction)delegate
			{
				ToggleNormal(entry.FileName, rowUi);
			});
			UnitEditorUiText.ReplaceButtonClick(val2, (UnityAction)delegate
			{
				ToggleDeath(entry.FileName, rowUi);
			});
			OggRows.Add(rowUi);
			RefreshOggRowVisual(rowUi);
		}

		private static void ToggleNormal(string fileName, OggRowUi rowUi)
		{
			if (!string.IsNullOrEmpty(fileName) && CustomVoiceOggCatalog.IsFileEligible(fileName))
			{
				bool value;
				bool flag = NormalByFile.TryGetValue(fileName, out value) && value;
				if (flag || CountNormalOn() < 5)
				{
					NormalByFile[fileName] = !flag;
					RefreshOggRowVisual(rowUi);
					UpdateSummary();
					RefreshAllOggToggleStates();
				}
			}
		}

		private static void ToggleDeath(string fileName, OggRowUi rowUi)
		{
			if (!string.IsNullOrEmpty(fileName) && CustomVoiceOggCatalog.IsFileEligible(fileName))
			{
				bool value;
				bool flag = DeathByFile.TryGetValue(fileName, out value) && value;
				if (flag || CountDeathOn() < 2)
				{
					DeathByFile[fileName] = !flag;
					RefreshOggRowVisual(rowUi);
					UpdateSummary();
					RefreshAllOggToggleStates();
				}
			}
		}

		private static void RefreshOggRowVisual(OggRowUi rowUi)
		{
			if (rowUi != null)
			{
				bool value;
				bool on = NormalByFile.TryGetValue(rowUi.FileName, out value) && value;
				bool value2;
				bool on2 = DeathByFile.TryGetValue(rowUi.FileName, out value2) && value2;
				SetToggleVisual(rowUi.NormalButton, rowUi.NormalLabel, on, "Normal");
				SetToggleVisual(rowUi.DeathButton, rowUi.DeathLabel, on2, "Death");
			}
		}

		private static void RefreshAllOggToggleStates()
		{
			bool flag = CountNormalOn() >= 5;
			bool flag2 = CountDeathOn() >= 2;
			for (int i = 0; i < OggRows.Count; i++)
			{
				OggRowUi oggRowUi = OggRows[i];
				bool value;
				bool flag3 = NormalByFile.TryGetValue(oggRowUi.FileName, out value) && value;
				bool value2;
				bool flag4 = DeathByFile.TryGetValue(oggRowUi.FileName, out value2) && value2;
				((Selectable)oggRowUi.NormalButton).interactable = flag3 || !flag;
				((Selectable)oggRowUi.DeathButton).interactable = flag4 || !flag2;
			}
		}

		private static void SetToggleVisual(Button button, Text label, bool on, string prefix)
		{
			//IL_0019: 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)
			if ((Object)(object)button != (Object)null)
			{
				((Graphic)((Component)button).GetComponent<Image>()).color = (on ? ToggleOn : ToggleOff);
			}
			if ((Object)(object)label != (Object)null)
			{
				label.text = (on ? (prefix + " ON") : prefix);
			}
		}

		private static int CountNormalOn()
		{
			return NormalByFile.Count((KeyValuePair<string, bool> kv) => kv.Value);
		}

		private static int CountDeathOn()
		{
			return DeathByFile.Count((KeyValuePair<string, bool> kv) => kv.Value);
		}

		private static void UpdateSummary()
		{
			if (!((Object)(object)_summaryText == (Object)null))
			{
				if (_view == CustomVoiceOverlayView.Hub)
				{
					_summaryText.text = $"{CustomVoiceStore.AllPacks.Count} saved voice(s) · {CustomVoiceOggCatalog.GetSummaryText()}";
					return;
				}
				if (CustomVoiceOggCatalog.ScanInProgress)
				{
					_summaryText.text = CustomVoiceOggCatalog.GetSummaryText();
					return;
				}
				_summaryText.text = $"Normal {CountNormalOn()}/{5} · Death {CountDeathOn()}/{2} · {CustomVoiceOggCatalog.GetSummaryText()}";
			}
		}

		private static bool MatchesSearch(string value)
		{
			if (string.IsNullOrWhiteSpace(_search))
			{
				return true;
			}
			return (value ?? string.Empty).IndexOf(_search, StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static void EquipPack(CustomVoicePack pack)
		{
			if (pack != null && CustomVoiceRegistry.TryGetBundle(pack.id, out var bundle))
			{
				UnitEditorManager obj = Object.FindObjectOfType<UnitEditorManager>();
				if (obj != null)
				{
					obj.EquipedVoiceBundle(bundle);
				}
				Close();
			}
		}

		private static void SavePack()
		{
			List<string> list = (from kv in NormalByFile
				where kv.Value && CustomVoiceOggCatalog.IsFileEligible(kv.Key)
				select kv.Key).Take(5).ToList();
			if (list.Count == 0)
			{
				Plugin.LogWarning("Custom voice: assign at least one Normal line before saving.");
				return;
			}
			List<string> list2 = (from kv in DeathByFile
				where kv.Value && CustomVoiceOggCatalog.IsFileEligible(kv.Key)
				select kv.Key).Take(2).ToList();
			if (list2.Count == 0)
			{
				Plugin.LogWarning("Custom voice: assign at least one Death line before saving.");
				return;
			}
			InputField packNameField = _packNameField;
			string text = ((packNameField == null) ? null : packNameField.text?.Trim());
			if (string.IsNullOrWhiteSpace(text))
			{
				text = "Custom Voice";
			}
			CustomVoicePack byId;
			if (!string.IsNullOrEmpty(_editingPackId))
			{
				byId = CustomVoiceStore.GetById(_editingPackId);
				if (byId == null)
				{
					return;
				}
				byId = byId.Clone();
			}
			else
			{
				byId = CustomVoicePack.CreateNew(text);
			}
			byId.name = text;
			byId.vocalFiles = list;
			byId.deathFiles = list2;
			CustomVoiceStore.Save(byId);
			if (CustomVoiceRegistry.TryGetBundle(byId.id, out var bundle))
			{
				UnitEditorManager obj = Object.FindObjectOfType<UnitEditorManager>();
				if (obj != null)
				{
					obj.EquipedVoiceBundle(bundle);
				}
				Close();
			}
		}

		private static void DeleteEditingPack()
		{
			if (!string.IsNullOrEmpty(_editingPackId))
			{
				string editingPackId = _editingPackId;
				CustomVoiceStore.Delete(editingPackId);
				CustomVoiceEditorHelper.RevertEquippedVoiceIfDeleted(editingPackId);
				_editingPackId = null;
				ShowHub();
			}
		}

		private static void DeletePack(CustomVoicePack pack)
		{
			if (pack != null && !string.IsNullOrEmpty(pack.id))
			{
				CustomVoiceStore.Delete(pack.id);
				CustomVoiceEditorHelper.RevertEquippedVoiceIfDeleted(pack.id);
				if (string.Equals(_editingPackId, pack.id, StringComparison.OrdinalIgnoreCase))
				{
					_editingPackId = null;
				}
				RefreshUi();
			}
		}

		private static void DeleteSourceFile(string fileName)
		{
			if (!string.IsNullOrEmpty(fileName) && CustomVoiceOggCatalog.TryDeleteSourceFile(fileName))
			{
				NormalByFile.Remove(fileName);
				DeathByFile.Remove(fileName);
				RefreshUi();
			}
		}

		private static void ClearListRows()
		{
			OggRows.Clear();
			if (!((Object)(object)_listContent == (Object)null))
			{
				for (int num = _listContent.childCount - 1; num >= 0; num--)
				{
					Object.Destroy((Object)(object)((Component)_listContent.GetChild(num)).gameObject);
				}
			}
		}

		private static GameObject CreateRowShell(int id)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			GameObject val = new GameObject("Row_" + id, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(LayoutElement)
			});
			val.transform.SetParent(_listContent, false);
			LayoutElement component = val.GetComponent<LayoutElement>();
			component.minHeight = 48f;
			component.preferredHeight = 48f;
			return val;
		}

		private static void CreateRowLabel(Transform parent, string text, float fontSize, Vector2 offsetMin, Vector2 offsetMax)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004d: 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)
			GameObject val = new GameObject("Label", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = offsetMin;
			component.offsetMax = offsetMax;
			Text obj = val.AddComponent<Text>();
			obj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			obj.fontSize = (int)fontSize;
			obj.alignment = (TextAnchor)3;
			((Graphic)obj).color = Color.white;
			obj.text = text;
		}

		private static void CreateRowIcon(Transform parent, Sprite sprite)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_005d: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Icon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0.5f);
			component.anchorMax = new Vector2(0f, 0.5f);
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(8f, 0f);
			component.sizeDelta = new Vector2(36f, 36f);
			val.GetComponent<Image>().sprite = sprite;
		}

		private static Button CreateSmallButton(Transform parent, string label, Vector2 anchoredPosition, Vector2 size, TextAnchor anchor)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			//IL_00a3: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Btn_" + label, new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			if ((int)anchor == 5)
			{
				component.anchorMin = new Vector2(1f, 0.5f);
				component.anchorMax = new Vector2(1f, 0.5f);
				component.pivot = new Vector2(1f, 0.5f);
			}
			else
			{
				component.anchorMin = new Vector2(0f, 0.5f);
				component.anchorMax = new Vector2(0f, 0.5f);
				component.pivot = new Vector2(0f, 0.5f);
			}
			component.anchoredPosition = anchoredPosition;
			component.sizeDelta = size;
			((Graphic)val.GetComponent<Image>()).color = ToggleOff;
			GameObject val2 = new GameObject("Label", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			Text obj = val2.AddComponent<Text>();
			obj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			obj.fontSize = 12;
			obj.alignment = (TextAnchor)4;
			((Graphic)obj).color = Color.white;
			obj.text = label;
			return val.GetComponent<Button>();
		}

		private static void EnsureBuilt()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0086: 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_013d: 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_0181: 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_01b8: 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_01f6: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: 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_034d: Expected O, but got Unknown
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Expected O, but got Unknown
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Expected O, but got Unknown
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0605: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_0664: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_073d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0761: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_079d: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0800: Unknown result type (might be due to invalid IL or missing references)
			//IL_081b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0835: Unknown result type (might be due to invalid IL or missing references)
			//IL_084f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c7: Expected O, but got Unknown
			//IL_089c: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0909: Unknown result type (might be due to invalid IL or missing references)
			//IL_092c: Unknown result type (might be due to invalid IL or missing references)
			//IL_093b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0973: Unknown result type (might be due to invalid IL or missing references)
			//IL_0982: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a2b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a44: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a67: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aa6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b11: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b29: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b34: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b5e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b74: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b80: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0869: Unknown result type (might be due to invalid IL or missing references)
			//IL_086e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0874: Expected O, but got Unknown
			if (HasStaleOverlayUi())
			{
				Object.Destroy((Object)(object)_canvasRoot);
				ResetOverlayRefs();
			}
			if (!((Object)(object)_canvasRoot != (Object)null))
			{
				_canvasRoot = new GameObject("TabsUnlimited_CustomVoiceOverlay", new Type[1] { typeof(RectTransform) });
				Object.DontDestroyOnLoad((Object)(object)_canvasRoot);
				Canvas obj = _canvasRoot.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 20000;
				CanvasScaler obj2 = _canvasRoot.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1280f, 720f);
				_canvasRoot.AddComponent<GraphicRaycaster>();
				GameObject val = CreatePanel(_canvasRoot.transform, "Backdrop", new Color(0f, 0f, 0f, 0.55f));
				StretchFull(val.GetComponent<RectTransform>());
				Button obj3 = val.AddComponent<Button>();
				((Selectable)obj3).targetGraphic = (Graphic)(object)val.GetComponent<Image>();
				object obj4 = <>O.<5>__Close;
				if (obj4 == null)
				{
					UnityAction val2 = Close;
					<>O.<5>__Close = val2;
					obj4 = (object)val2;
				}
				UnitEditorUiText.ReplaceButtonClick(obj3, (UnityAction)obj4);
				_panel = CreatePanel(_canvasRoot.transform, "Panel", new Color(0.06f, 0.06f, 0.07f, 0.98f));
				RectTransform component = _panel.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.06f, 0.06f);
				component.anchorMax = new Vector2(0.94f, 0.94f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				GameObject val3 = CreatePanel(_panel.transform, "Header", new Color(0.08f, 0.08f, 0.09f, 1f));
				_headerRect = val3.GetComponent<RectTransform>();
				_headerRect.anchorMin = new Vector2(0f, 1f);
				_headerRect.anchorMax = new Vector2(1f, 1f);
				_headerRect.pivot = new Vector2(0.5f, 1f);
				_headerRect.sizeDelta = new Vector2(0f, 148f);
				_headerRect.anchoredPosition = Vector2.zero;
				_titleText = CreateStaticText(val3.transform, "Title", 18, (TextAnchor)0, new Vector2(16f, -8f), new Vector2(-120f, -28f), "CUSTOM VOICES");
				_instructionsText = CreateStaticText(val3.transform, "Instructions", 12, (TextAnchor)0, new Vector2(16f, -42f), new Vector2(-16f, -96f), string.Empty);
				((Graphic)_instructionsText).color = new Color(0.72f, 0.72f, 0.75f, 1f);
				_instructionsText.horizontalOverflow = (HorizontalWrapMode)0;
				_instructionsText.verticalOverflow = (VerticalWrapMode)1;
				_summaryText = CreateStaticText(val3.transform, "Summary", 13, (TextAnchor)0, new Vector2(16f, -100f), new Vector2(-16f, -120f), string.Empty);
				_packNameContainer = new GameObject("PackNameRow", new Type[1] { typeof(RectTransform) });
				_packNameContainer.transform.SetParent(val3.transform, false);
				RectTransform component2 = _packNameContainer.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 1f);
				component2.anchorMax = new Vector2(0f, 1f);
				component2.pivot = new Vector2(0f, 1f);
				component2.anchoredPosition = new Vector2(16f, -124f);
				component2.sizeDelta = new Vector2(280f, 24f);
				GameObject val4 = new GameObject("PackNameInput", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val4.transform.SetParent(_packNameContainer.transform, false);
				RectTransform component3 = val4.GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(0f, 0f);
				component3.anchorMax = new Vector2(1f, 1f);
				component3.offsetMin = Vector2.zero;
				component3.offsetMax = Vector2.zero;
				((Graphic)val4.GetComponent<Image>()).color = new Color(0.14f, 0.14f, 0.16f, 1f);
				GameObject val5 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
				val5.transform.SetParent(val4.transform, false);
				StretchFull(val5.GetComponent<RectTransform>(), 8f, 2f, -8f, -2f);
				Text val6 = val5.AddComponent<Text>();
				val6.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				val6.fontSize = 14;
				((Graphic)val6).color = Color.white;
				val6.supportRichText = false;
				_packNameField = val4.AddComponent<InputField>();
				_packNameField.textComponent = val6;
				_packNameField.placeholder = (Graphic)(object)CreateInputPlaceholder(val4.transform, "Name");
				_packNameField.text = string.Empty;
				_packNameContainer.SetActive(false);
				GameObject val7 = new GameObject("Search", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val7.transform.SetParent(val3.transform, false);
				_searchRect = val7.GetComponent<RectTransform>();
				_searchRect.anchorMin = new Vector2(0f, 0f);
				_searchRect.anchorMax = new Vector2(1f, 0f);
				_searchRect.pivot = new Vector2(0.5f, 0f);
				_searchRect.anchoredPosition = new Vector2(0f, 12f);
				_searchRect.sizeDelta = new Vector2(-140f, 32f);
				((Graphic)val7.GetComponent<Image>()).color = new Color(0.14f, 0.14f, 0.16f, 1f);
				GameObject val8 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
				val8.transform.SetParent(val7.transform, false);
				StretchFull(val8.GetComponent<RectTransform>(), 8f, 4f, -8f, -4f);
				Text val9 = val8.AddComponent<Text>();
				val9.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				val9.fontSize = 14;
				((Graphic)val9).color = Color.white;
				val9.supportRichText = false;
				_searchField = val7.AddComponent<InputField>();
				_searchField.textComponent = val9;
				_searchField.placeholder = (Graphic)(object)CreateInputPlaceholder(val7.transform, "Search");
				((UnityEvent<string>)(object)_searchField.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
				{
					_search = value ?? string.Empty;
					RefreshUi();
				});
				_openFolderButton = CreateSmallButton(val3.transform, "Open File", new Vector2(-112f, 12f), new Vector2(96f, 32f), (TextAnchor)5);
				((Component)_openFolderButton).GetComponent<RectTransform>().anchorMin = new Vector2(1f, 0f);
				((Component)_openFolderButton).GetComponent<RectTransform>().anchorMax = new Vector2(1f, 0f);
				((Component)_openFolderButton).GetComponent<RectTransform>().pivot = new Vector2(1f, 0f);
				Button openFolderButton = _openFolderButton;
				object obj5 = <>O.<6>__OpenSourcesFolder;
				if (obj5 == null)
				{
					UnityAction val10 = CustomVoiceOggImporter.OpenSourcesFolder;
					<>O.<6>__OpenSourcesFolder = val10;
					obj5 = (object)val10;
				}
				UnitEditorUiText.ReplaceButtonClick(openFolderButton, (UnityAction)obj5);
				((Component)_openFolderButton).gameObject.SetActive(false);
				Button obj6 = CreateSmallButton(val3.transform, "Close", new Vector2(-12f, -12f), new Vector2(96f, 32f), (TextAnchor)5);
				((Component)obj6).GetComponent<RectTransform>().anchorMin = new Vector2(1f, 1f);
				((Component)obj6).GetComponent<RectTransform>().anchorMax = new Vector2(1f, 1f);
				((Component)obj6).GetComponent<RectTransform>().pivot = new Vector2(1f, 1f);
				object obj7 = <>O.<5>__Close;
				if (obj7 == null)
				{
					UnityAction val11 = Close;
					<>O.<5>__Close = val11;
					obj7 = (object)val11;
				}
				UnitEditorUiText.ReplaceButtonClick(obj6, (UnityAction)obj7);
				_footer = CreatePanel(_panel.transform, "Footer", new Color(0.08f, 0.08f, 0.09f, 1f));
				RectTransform component4 = _footer.GetComponent<RectTransform>();
				component4.anchorMin = new Vector2(0f, 0f);
				component4.anchorMax = new Vector2(1f, 0f);
				component4.pivot = new Vector2(0.5f, 0f);
				component4.sizeDelta = new Vector2(0f, 52f);
				component4.anchoredPosition = Vector2.zero;
				_footerSecondary = CreateSmallButton(_footer.transform, "Back", new Vector2(16f, 10f), new Vector2(96f, 32f), (TextAnchor)3);
				_footerSecondaryLabel = ((Component)_footerSecondary).GetComponentInChildren<Text>();
				_footerDelete = CreateSmallButton(_footer.transform, "Delete", new Vector2(120f, 10f), new Vector2(96f, 32f), (TextAnchor)3);
				_footerPrimary = CreateSmallButton(_footer.transform, "Save", new Vector2(-16f, 10f), new Vector2(96f, 32f), (TextAnchor)5);
				_footerPrimaryLabel = ((Component)_footerPrimary).GetComponentInChildren<Text>();
				GameObject val12 = new GameObject("ScrollHost", new Type[1] { typeof(RectTransform) });
				val12.transform.SetParent(_panel.transform, false);
				_scrollHostRect = val12.GetComponent<RectTransform>();
				_scrollHostRect.anchorMin = Vector2.zero;
				_scrollHostRect.anchorMax = Vector2.one;
				_scrollHostRect.offsetMin = new Vector2(8f, 56f);
				_scrollHostRect.offsetMax = new Vector2(-8f, -152f);
				_scrollRect = val12.AddComponent<ScrollRect>();
				_scrollRect.horizontal = false;
				_scrollRect.movementType = (MovementType)2;
				GameObject val13 = CreatePanel(val12.transform, "Viewport", new Color(0f, 0f, 0f, 0.15f));
				StretchFull(val13.GetComponent<RectTransform>());
				val13.AddComponent<Mask>().showMaskGraphic = false;
				GameObject val14 = new GameObject("Content", new Type[3]
				{
					typeof(RectTransform),
					typeof(VerticalLayoutGroup),
					typeof(ContentSizeFitter)
				});
				val14.transform.SetParent(val13.transform, false);
				_listContent = val14.transform;
				RectTransform component5 = val14.GetComponent<RectTransform>();
				component5.anchorMin = new Vector2(0f, 1f);
				component5.anchorMax = new Vector2(1f, 1f);
				component5.pivot = new Vector2(0.5f, 1f);
				component5.anchoredPosition = Vector2.zero;
				component5.sizeDelta = new Vector2(0f, 0f);
				VerticalLayoutGroup component6 = val14.GetComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)component6).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)component6).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)component6).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component6).spacing = 2f;
				val14.GetComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
				_scrollRect.viewport = val13.GetComponent<RectTransform>();
				_scrollRect.content = component5;
				_canvasRoot.SetActive(false);
			}
		}

		private static bool HasStaleOverlayUi()
		{
			if ((Object)(object)_canvasRoot == (Object)null)
			{
				return false;
			}
			if ((Object)(object)_instructionsText == (Object)null)
			{
				return true;
			}
			Transform[] componentsInChildren = _canvasRoot.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (((Object)componentsInChildren[i]).name == "Btn_Add OGG")
				{
					return true;
				}
			}
			return false;
		}

		private static void ResetOverlayRefs()
		{
			_canvasRoot = null;
			_panel = null;
			_headerRect = null;
			_scrollHostRect = null;
			_titleText = null;
			_instructionsText = null;
			_summaryText = null;
			_searchField = null;
			_searchRect = null;
			_packNameContainer = null;
			_packNameField = null;
			_openFolderButton = null;
			_listContent = null;
			_scrollRect = null;
			_footer = null;
			_footerPrimary = null;
			_footerSecondary = null;
			_footerDelete = null;
			_footerPrimaryLabel = null;
			_footerSecondaryLabel = null;
		}

		private static GameObject CreatePanel(Transform parent, string name, Color color)
		{
			//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_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_0040: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = color;
			return val;
		}

		private static Text CreateInputPlaceholder(Transform parent, string placeholderText)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Placeholder", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			StretchFull(val.GetComponent<RectTransform>(), 8f, 2f, -8f, -2f);
			Text obj = val.AddComponent<Text>();
			obj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			obj.fontSize = 14;
			obj.fontStyle = (FontStyle)2;
			((Graphic)obj).color = new Color(0.55f, 0.55f, 0.58f, 1f);
			obj.text = placeholderText;
			obj.supportRichText = false;
			return obj;
		}

		private static Text CreateStaticText(Transform parent, string name, int fontSize, TextAnchor anchor, Vector2 offsetMin, Vector2 offsetMax, string text)
		{
			//IL_0014: 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)
			//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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.offsetMin = offsetMin;
			component.offsetMax = offsetMax;
			Text obj = val.AddComponent<Text>();
			obj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			obj.fontSize = fontSize;
			obj.alignment = anchor;
			((Graphic)obj).color = Color.white;
			obj.text = text;
			return obj;
		}

		private static void StretchFull(RectTransform rect, float left = 0f, float bottom = 0f, float right = 0f, float top = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = new Vector2(left, bottom);
			rect.offsetMax = new Vector2(0f - right, 0f - top);
		}
	}
	internal static class EcsComponentHelper
	{
		private static readonly Type GameObjectEntityType = AccessTools.TypeByName("GameObjectEntity") ?? AccessTools.TypeByName("Unity.Entities.Hybrid.GameObjectEntity, Unity.Entities.Hybrid");

		private static readonly PropertyInfo GoEntityEntityProperty = ((GameObjectEntityType != null) ? AccessTools.Property(GameObjectEntityType, "Entity") : null);

		private static readonly PropertyInfo GoEntityManagerProperty = ((GameObjectEntityType != null) ? AccessTools.Property(GameObjectEntityType, "EntityManager") : null);

		private static readonly PropertyInfo WorldActiveProperty = AccessTools.Property(typeof(World), "Active");

		private static readonly MethodInfo GetExistingManagerMethod = AccessTools.Method(typeof(World), "GetExistingManager", (Type[])null, (Type[])null);

		internal static bool IsAvailable
		{
			get
			{
				if (GameObjectEntityType != null && GoEntityEntityProperty != null && GoEntityManagerProperty != null && WorldActiveProperty != null)
				{
					return GetExistingManagerMethod != null;
				}
				return false;
			}
		}

		internal static World GetActiveWorld()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			return (World)(WorldActiveProperty?.GetValue(null, null));
		}

		internal static TManager GetExistingManager<TManager>() where TManager : class
		{
			World activeWorld = GetActiveWorld();
			if (activeWorld == null || GetExistingManagerMethod == null)
			{
				return null;
			}
			return (TManager)GetExistingManagerMethod.MakeGenericMethod(typeof(TManager)).Invoke(activeWorld, null);
		}

		internal static bool TryGetEntityManager(Component component, out Entity entity, out EntityManager entityManager)
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			entity = Entity.Null;
			entityManager = null;
			if ((Object)(object)component == (Object)null || GameObjectEntityType == null)
			{
				return false;
			}
			Component component2 = component.GetComponent(GameObjectEntityType);
			if ((Object)(object)component2 == (Object)null)
			{
				return false;
			}
			entity = (Entity)GoEntityEntityProperty.GetValue(component2, null);
			entityManager = (EntityManager)GoEntityManagerProperty.GetValue(component2, null);
			return entityManager.IsCreated;
		}

		internal static bool TryGetComponentData<T>(EntityManager entityManager, Entity entity, out T data) where T : struct, IComponentData
		{
			//IL_0010: 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)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			data = default(T);
			if (!entityManager.IsCreated || !entityManager.Exists(entity) || !entityManager.HasComponent<T>(entity))
			{
				return false;
			}
			data = entityManager.GetComponentData<T>(entity);
			return true;
		}
	}
	[Serializable]
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct EnemyHighestPriceTargeting : ITargetingComponent, IComponentData
	{
	}
	[Serializable]
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct EnemyLowestHealthTargeting : ITargetingComponent, IComponentData
	{
	}
	[Serializable]
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct EnemyRangedMixedTargeting : ITargetingComponent, IComponentData
	{
	}
	internal static class FleeDistanceEditorDefaults
	{
		internal const bool RangedUntilFleeEnabled = true;

		internal const float Default = 5f;

		internal const float Min = 1f;

		internal const float Max = 30f;
	}
	internal static class FleeDistanceHelper
	{
		private const float RangedAttackRangeThreshold = 5f;

		private const float FallbackWaitingDistance = 100f;

		private const float WeaponRangeBuffer = 0.3f;

		private static readonly Dictionary<int, float> DistanceByBlueprintId = new Dictionary<int, float>();

		private static readonly Dictionary<DatabaseID, float> DistanceByBlueprintGuid = new Dictionary<DatabaseID, float>();

		private static float? _cachedVanillaWaitingDistance;

		internal static bool HasKeepRangedDistanceMovement(IReadOnlyList<IMovementComponent> movementComponents)
		{
			if (movementComponents == null)
			{
				return false;
			}
			for (int i = 0; i < movementComponents.Count; i++)
			{
				if (movementComponents[i] is KeepRangedDistance)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool HasFleeDistanceMovement(IReadOnlyList<IMovementComponent> movementComponents)
		{
			if (movementComponents == null)
			{
				return false;
			}
			for (int i = 0; i < movementComponents.Count; i++)
			{
				if (movementComponents[i] is FleeDistance)
				{
					return true;
				}
			}
			return false;
		}

		internal static float ReadComponentFleeDistance(UnitBlueprint blueprint)
		{
			return ReadFromMovementComponents(blueprint?.MovementComponents);
		}

		internal static bool TryGetCachedDistance(UnitBlueprint blueprint, out float distance)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			distance = 0f;
			if ((Object)(object)blueprint == (Object)null)
			{
				return false;
			}
			int instanceID = ((Object)blueprint).GetInstanceID();
			if (DistanceByBlueprintId.TryGetValue(instanceID, out distance) && distance > 0f)
			{
				return true;
			}
			if (blueprint.Entity == null)
			{
				return false;
			}
			DatabaseID gUID = blueprint.Entity.GUID;
			if (gUID == default(DatabaseID))
			{
				return false;
			}
			if (!DistanceByBlueprintGuid.TryGetValue(gUID, out distance) || distance <= 0f)
			{
				return false;
			}
			DistanceByBlueprintId[instanceID] = distance;
			return true;
		}

		internal static float GetFleeDistance(UnitBlueprint blueprint)
		{
			if ((Object)(object)blueprint == (Object)null)
			{
				return 5f;
			}
			float num = ReadFromMovementComponents(blueprint.MovementComponents);
			if (TryGetCachedDistance(blueprint, out var distance) && (num <= 0f || (Mathf.Approximately(num, 5f) && !Mathf.Approximately(distance, num))))
			{
				return distance;
			}
			if (num > 0f)
			{
				return num;
			}
			return 5f;
		}

		internal static void SetFleeDistance(UnitBlueprint blueprint, float distanceMeters)
		{
			if (!((Object)(object)blueprint == (Object)null))
			{
				distanceMeters = ClampDistance(distanceMeters);
				CacheDistance(blueprint, distanceMeters);
				EnsureFleeDistanceComponent(blueprint, distanceMeters);
			}
		}

		internal static void EnsureFleeDistanceComponent(UnitBlueprint blueprint, float distanceMeters)