Decompiled source of Foreign forces v1.1.1

Foreign_forces.dll

Decompiled 5 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.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using DM;
using HarmonyLib;
using Landfall.TABC;
using Landfall.TABS;
using Landfall.TABS.AI.Components;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.AI.Systems;
using Landfall.TABS.Budget;
using Landfall.TABS.Budget.Wallets;
using Landfall.TABS.GameMode;
using Landfall.TABS.GameState;
using Landfall.TABS.UI;
using Landfall.TABS.UI.BattleUI;
using Landfall.TABS.UnitPlacement;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using LevelCreator;
using Newtonsoft.Json;
using Photon.Bolt;
using TFBGames;
using TMPro;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Mod_Name;

internal static class AddTargetableEffectExplosionTeamFix
{
	public static void ApplyPatches()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0025: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[AddTargetableEffectExplosionTeamFix] 正在应用 AddTargetableEffect Explosion 队伍判断修复补丁...");
			Harmony val = new Harmony("Mod_Name.AddTargetableEffectExplosionTeamFix");
			PatchAddTargetableEffectDoEffect(val);
			PatchExplosionExplode(val);
			PatchExplosionStart(val);
			Debug.Log((object)"[AddTargetableEffectExplosionTeamFix] AddTargetableEffect Explosion 队伍判断修复补丁应用完成!");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[AddTargetableEffectExplosionTeamFix] 应用补丁时发生错误: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void PatchAddTargetableEffectDoEffect(Harmony harmony)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		MethodInfo method = typeof(AddTargetableEffect).GetMethod("DoEffect", new Type[2]
		{
			typeof(Transform),
			typeof(Transform)
		});
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(AddTargetableEffectExplosionTeamFix).GetMethod("AddTargetableEffect_DoEffect_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Debug.Log((object)"[AddTargetableEffectExplosionTeamFix] 已补丁 AddTargetableEffect.DoEffect(Transform, Transform)");
		}
		else
		{
			Debug.LogWarning((object)"[AddTargetableEffectExplosionTeamFix] 未找到 AddTargetableEffect.DoEffect(Transform, Transform) 方法");
		}
	}

	private static bool AddTargetableEffect_DoEffect_Prefix(AddTargetableEffect __instance, Transform startPoint, Transform target)
	{
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			DataHandler componentInChildren = ((Component)((Component)target).transform.root).GetComponentInChildren<DataHandler>();
			if ((Object)(object)componentInChildren == (Object)null || componentInChildren.Dead || !Object.op_Implicit((Object)(object)componentInChildren))
			{
				return true;
			}
			UnitEffectBase val = UnitEffectBase.AddEffectToTarget(((Component)target).gameObject, __instance.EffectPrefab);
			if ((Object)(object)val != (Object)null)
			{
				val.Ping();
				return false;
			}
			FieldInfo? field = typeof(AddTargetableEffect).GetField("unit", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(AddTargetableEffect).GetField("rootTeamHolder", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = field?.GetValue(__instance);
			Unit val2 = (Unit)((obj is Unit) ? obj : null);
			object? obj2 = field2?.GetValue(__instance);
			TeamHolder val3 = (TeamHolder)((obj2 is TeamHolder) ? obj2 : null);
			if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				TeamHolder.GetTeamRelevantComponents(((Component)__instance).transform.root, ref val2, ref val3);
			}
			UnitEffectBase val4 = Object.Instantiate<UnitEffectBase>(__instance.EffectPrefab, ((Component)target).transform.root);
			((Component)val4).transform.position = ((Component)target).transform.root.position;
			val4.damageMultiplier = ((TargetableEffect)__instance).damageMultiplier;
			TeamHolder val5 = TeamHolder.AddTeamHolder(((Component)val4).gameObject, val2, val3);
			Explosion[] componentsInChildren = ((Component)val4).GetComponentsInChildren<Explosion>();
			foreach (Explosion val6 in componentsInChildren)
			{
				if (!((Object)(object)val6 != (Object)null))
				{
					continue;
				}
				FieldInfo field3 = typeof(Explosion).GetField("teamHolder", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field3 != null && (Object)(object)val5 != (Object)null)
				{
					field3.SetValue(val6, val5);
				}
				if (val6.automatic && (Object)(object)val5 != (Object)null)
				{
					FieldInfo field4 = typeof(Explosion).GetField("team", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field4 != null)
					{
						field4.SetValue(val6, val5.team);
					}
				}
			}
			val4.DoEffect();
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[AddTargetableEffectExplosionTeamFix] AddTargetableEffect_DoEffect_Prefix 执行失败: " + ex.Message + "\n" + ex.StackTrace));
			return true;
		}
	}

	private static void PatchExplosionExplode(Harmony harmony)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		MethodInfo method = typeof(Explosion).GetMethod("Explode", BindingFlags.Instance | BindingFlags.Public);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(AddTargetableEffectExplosionTeamFix).GetMethod("Explosion_Explode_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Debug.Log((object)"[AddTargetableEffectExplosionTeamFix] 已补丁 Explosion.Explode()");
		}
		else
		{
			Debug.LogWarning((object)"[AddTargetableEffectExplosionTeamFix] 未找到 Explosion.Explode() 方法");
		}
	}

	private static bool Explosion_Explode_Prefix(Explosion __instance)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: 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_01ad: 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_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: 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_01ff: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			__instance.Start();
			FieldInfo field = typeof(Explosion).GetField("teamHolder", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(Explosion).GetField("team", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeof(Explosion).GetField("ownUnit", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = field?.GetValue(__instance);
			TeamHolder val = (TeamHolder)((obj is TeamHolder) ? obj : null);
			Team val2 = (Team)(((object)field2 != null && field2.GetValue(__instance) != null) ? ((int)(Team)field2.GetValue(__instance)) : 0);
			object? obj2 = field3?.GetValue(__instance);
			Unit val3 = (Unit)((obj2 is Unit) ? obj2 : null);
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)__instance).GetComponentInParent<TeamHolder>();
			}
			if ((Object)(object)val == (Object)null)
			{
				Transform parent = ((Component)__instance).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)val == (Object)null)
				{
					val = ((Component)parent).GetComponent<TeamHolder>();
					if ((Object)(object)val == (Object)null)
					{
						parent = parent.parent;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				val2 = val.team;
				if ((Object)(object)val.spawner != (Object)null)
				{
					val3 = val.spawner.GetComponentInParent<Unit>();
				}
				if (field != null)
				{
					field.SetValue(__instance, val);
				}
				if (field2 != null)
				{
					field2.SetValue(__instance, val2);
				}
				if (field3 != null && (Object)(object)val3 != (Object)null)
				{
					field3.SetValue(__instance, val3);
				}
			}
			else
			{
				Unit component = ((Component)((Component)__instance).transform.root).GetComponent<Unit>();
				if ((Object)(object)component != (Object)null)
				{
					TeamHolder component2 = ((Component)component).GetComponent<TeamHolder>();
					if ((Object)(object)component2 != (Object)null && (Object)(object)component2.spawner == (Object)(object)((Component)component).gameObject)
					{
						val2 = component.Team;
						val3 = component;
					}
					else
					{
						TeamHolder componentInChildren = ((Component)((Component)__instance).transform.root).GetComponentInChildren<TeamHolder>();
						if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.spawner != (Object)null)
						{
							Unit componentInParent = componentInChildren.spawner.GetComponentInParent<Unit>();
							if ((Object)(object)componentInParent != (Object)null)
							{
								val2 = componentInParent.Team;
								val3 = componentInParent;
							}
							else
							{
								val2 = component.Team;
								val3 = component;
							}
						}
						else
						{
							val2 = component.Team;
							val3 = component;
						}
					}
					if (field2 != null)
					{
						field2.SetValue(__instance, val2);
					}
					if (field3 != null && (Object)(object)val3 != (Object)null)
					{
						field3.SetValue(__instance, val3);
					}
				}
			}
			return true;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[AddTargetableEffectExplosionTeamFix] Explosion_Explode_Prefix 执行失败: " + ex.Message + "\n" + ex.StackTrace));
			return true;
		}
	}

	private static void PatchExplosionStart(Harmony harmony)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		MethodInfo method = typeof(Explosion).GetMethod("Start", BindingFlags.Instance | BindingFlags.Public);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(AddTargetableEffectExplosionTeamFix).GetMethod("Explosion_Start_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Debug.Log((object)"[AddTargetableEffectExplosionTeamFix] 已补丁 Explosion.Start()");
		}
		else
		{
			Debug.LogWarning((object)"[AddTargetableEffectExplosionTeamFix] 未找到 Explosion.Start() 方法");
		}
	}

	private static void Explosion_Start_Postfix(Explosion __instance)
	{
		try
		{
			FieldInfo field = typeof(Explosion).GetField("teamHolder", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = field?.GetValue(__instance);
			TeamHolder val = (TeamHolder)((obj is TeamHolder) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				return;
			}
			val = ((Component)__instance).GetComponentInParent<TeamHolder>();
			if ((Object)(object)val == (Object)null)
			{
				Transform parent = ((Component)__instance).transform.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)val == (Object)null)
				{
					val = ((Component)parent).GetComponent<TeamHolder>();
					if ((Object)(object)val == (Object)null)
					{
						parent = parent.parent;
					}
				}
			}
			if (field != null && (Object)(object)val != (Object)null)
			{
				field.SetValue(__instance, val);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[AddTargetableEffectExplosionTeamFix] Explosion_Start_Postfix 执行失败: " + ex.Message));
		}
	}
}
internal static class BattleBudgetPatches
{
	private static Type s_lastWalletType;

	public static void ApplyPatches()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[BattleBudgetPatches] 正在应用BattleBudget补丁...");
			Harmony val = new Harmony("Mod_Name.BattleBudget");
			MethodInfo method = typeof(BattleBudget).GetMethod("SetBudget", new Type[1] { typeof(int) });
			if (method != null)
			{
				val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_SetBudget_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			PatchDictionaryAccessMethods(val);
			Debug.Log((object)"[BattleBudgetPatches] BattleBudget补丁应用完成!");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[BattleBudgetPatches] 应用补丁时发生错误: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void PatchDictionaryAccessMethods(Harmony harmony)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Expected O, but got Unknown
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Expected O, but got Unknown
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Expected O, but got Unknown
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Expected O, but got Unknown
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Expected O, but got Unknown
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Expected O, but got Unknown
		MethodInfo method = typeof(BattleBudget).GetMethod("CanAfford", new Type[2]
		{
			typeof(Team),
			typeof(int)
		});
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_CanAfford_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method2 = typeof(BattleBudget).GetMethod("GetBudget", new Type[1] { typeof(Team) });
		if (method2 != null)
		{
			harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_GetBudget_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method3 = typeof(BattleBudget).GetMethod("GetMaxBudget", new Type[1] { typeof(Team) });
		if (method3 != null)
		{
			harmony.Patch((MethodBase)method3, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_GetMaxBudget_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method4 = typeof(BattleBudget).GetMethod("ReturnAmount", new Type[2]
		{
			typeof(Team),
			typeof(int)
		});
		if (method4 != null)
		{
			harmony.Patch((MethodBase)method4, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_ReturnAmount_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method5 = typeof(BattleBudget).GetMethod("SpendAmount", new Type[2]
		{
			typeof(Team),
			typeof(int)
		});
		if (method5 != null)
		{
			harmony.Patch((MethodBase)method5, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_SpendAmount_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method6 = typeof(BattleBudget).GetMethod("IsInfinite", new Type[1] { typeof(Team) });
		if (method6 != null)
		{
			harmony.Patch((MethodBase)method6, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_IsInfinite_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method7 = typeof(BattleBudget).GetMethod("SetBudget", new Type[2]
		{
			typeof(Team),
			typeof(int)
		});
		if (method7 != null)
		{
			harmony.Patch((MethodBase)method7, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_SetBudgetTeam_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method8 = typeof(BattleBudget).GetMethod("ResetBudget", new Type[1] { typeof(Team) });
		if (method8 != null)
		{
			harmony.Patch((MethodBase)method8, new HarmonyMethod(typeof(BattleBudgetPatches).GetMethod("BattleBudget_ResetBudget_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void BattleBudget_SetBudget_Postfix(BattleBudget __instance, int budget)
	{
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		bool flag2 = false;
		try
		{
			GameModeService service = ServiceLocator.GetService<GameModeService>();
			if ((Object)(object)service != (Object)null && service.CurrentGameMode != null)
			{
				flag2 = ((object)service.CurrentGameMode).GetType().Name == "SandboxGameMode";
			}
			FieldInfo field = typeof(BattleBudget).GetField("m_teamBudgets", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null && field.GetValue(__instance) is Dictionary<Team, BaseWallet> { Count: >0 } dictionary)
			{
				foreach (BaseWallet value in dictionary.Values)
				{
					if (value != null && (((object)value).GetType().Name == "CampaignWallet" || flag2))
					{
						flag = true;
						break;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[BattleBudgetPatches] 检查钱包类型时出错: " + ex.Message));
		}
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		foreach (Team val in allTeamsIncludingExtended)
		{
			if (!TeamEnumExtension.IsExtendedTeam(val))
			{
				continue;
			}
			EnsureTeamExists(__instance, val);
			int num = ((!flag) ? budget : 0);
			MethodInfo method = typeof(BattleBudget).GetMethod("SetBudget", new Type[2]
			{
				typeof(Team),
				typeof(int)
			});
			if (method != null)
			{
				method.Invoke(__instance, new object[2] { val, num });
				if (flag)
				{
					string text = (flag2 ? "Sandbox模式" : "使用CampaignWallet");
					Debug.Log((object)("[BattleBudgetPatches] " + text + ":为扩展队伍 " + TeamEnumExtension.GetTeamName(val) + " 设置无限预算(0)"));
				}
			}
		}
	}

	private static bool BattleBudget_CanAfford_Prefix(BattleBudget __instance, Team team, int price)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_GetBudget_Prefix(BattleBudget __instance, Team team)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_GetMaxBudget_Prefix(BattleBudget __instance, Team team)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_ReturnAmount_Prefix(BattleBudget __instance, Team team, int amount)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_SpendAmount_Prefix(BattleBudget __instance, Team team, int amount)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_IsInfinite_Prefix(BattleBudget __instance, Team team)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_SetBudgetTeam_Prefix(BattleBudget __instance, Team team, int budget)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static bool BattleBudget_ResetBudget_Prefix(BattleBudget __instance, Team team)
	{
		//IL_0000: 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)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			EnsureTeamExists(__instance, team);
		}
		return true;
	}

	private static void EnsureTeamExists(BattleBudget instance, Team team)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01dd: 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_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(BattleBudget).GetField("m_teamBudgets", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			Debug.LogWarning((object)"[BattleBudgetPatches] 无法找到 m_teamBudgets 字段");
		}
		else if (!(field.GetValue(instance) is Dictionary<Team, BaseWallet> dictionary))
		{
			Debug.LogWarning((object)"[BattleBudgetPatches] teamBudgets 字典为 null");
		}
		else
		{
			if (dictionary.ContainsKey(team))
			{
				return;
			}
			if (dictionary.Count != 0)
			{
				Type type = null;
				try
				{
					GameModeService service = ServiceLocator.GetService<GameModeService>();
					if ((Object)(object)service != (Object)null && service.CurrentGameMode != null)
					{
						Type type2 = ((object)service.CurrentGameMode).GetType();
						if (type2.Name == "CampaignGameMode")
						{
							type = typeof(CampaignWallet);
						}
						else if (type2.Name == "SandboxGameMode")
						{
							type = typeof(SandboxWallet);
						}
						else if (type2.Name == "LocalMultiplayerGameMode" || type2.Name == "OnlineMultiplayerGameMode")
						{
							type = typeof(LocalMultiplayerWallet);
						}
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[BattleBudgetPatches] EnsureTeamExists: 检查游戏模式时出错: " + ex.Message));
				}
				if (type == null)
				{
					BaseWallet val = null;
					foreach (BaseWallet value in dictionary.Values)
					{
						if (value != null)
						{
							val = value;
							if (s_lastWalletType == null)
							{
								s_lastWalletType = ((object)value).GetType();
							}
							break;
						}
					}
					if (val == null)
					{
						Debug.LogWarning((object)("[BattleBudgetPatches] 无法为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 创建钱包:找不到模板钱包"));
						return;
					}
					type = s_lastWalletType ?? ((object)val).GetType();
					if (type == null)
					{
						type = ((object)val).GetType();
					}
				}
				try
				{
					BaseWallet val2 = (BaseWallet)Activator.CreateInstance(type);
					val2.SetTeamOwner(team);
					bool num = type.Name == "CampaignWallet";
					FieldInfo field2 = typeof(BattleBudget).GetField("m_originalBudget", BindingFlags.Instance | BindingFlags.NonPublic);
					int num2 = 0;
					if (field2 != null)
					{
						num2 = (int)field2.GetValue(instance);
					}
					if (num2 == 0 && dictionary.ContainsKey((Team)0))
					{
						num2 = dictionary[(Team)0].GetBudget();
					}
					if (num2 == 0 && dictionary.ContainsKey((Team)1))
					{
						num2 = dictionary[(Team)1].GetBudget();
					}
					if (num)
					{
						num2 = 0;
						Debug.Log((object)("[BattleBudgetPatches] EnsureTeamExists: 使用CampaignWallet:为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 设置无限预算(0)"));
					}
					val2.SetBudget(num2);
					dictionary[team] = val2;
					Debug.Log((object)$"[BattleBudgetPatches] 自动为扩展队伍 {TeamEnumExtension.GetTeamName(team)} 创建了钱包,类型: {type.Name}, 预算: {num2}");
					return;
				}
				catch (Exception ex2)
				{
					Debug.LogError((object)("[BattleBudgetPatches] 创建钱包失败: " + ex2.Message + "\n" + ex2.StackTrace));
					return;
				}
			}
			Debug.LogWarning((object)("[BattleBudgetPatches] 无法为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 创建钱包:字典为空,可能尚未初始化"));
		}
	}
}
internal static class BattleUIControllerPatches
{
	public static void ApplyPatches()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[BattleUIControllerPatches] 正在应用 BattleUIController 补丁...");
			Harmony val = new Harmony("Mod_Name.BattleUIController");
			MethodInfo method = typeof(BattleUIController).GetMethod("OnEnterBattleState", BindingFlags.Instance | BindingFlags.Public);
			if (method != null)
			{
				val.Patch((MethodBase)method, new HarmonyMethod(typeof(BattleUIControllerPatches).GetMethod("OnEnterBattleState_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				MethodInfo method2 = typeof(BattleUIController).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method2 != null)
				{
					val.Patch((MethodBase)method2, new HarmonyMethod(typeof(BattleUIControllerPatches).GetMethod("Update_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				MethodInfo method3 = typeof(WinConditionTimerUI).GetMethod("SetTeamText", new Type[1] { typeof(Team) });
				if (method3 != null)
				{
					val.Patch((MethodBase)method3, new HarmonyMethod(typeof(BattleUIControllerPatches).GetMethod("SetTeamText_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				Debug.Log((object)"[BattleUIControllerPatches] BattleUIController 补丁应用完成!");
			}
			else
			{
				Debug.LogWarning((object)"[BattleUIControllerPatches] 未找到 BattleUIController.OnEnterBattleState 方法");
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[BattleUIControllerPatches] 应用补丁失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static bool OnEnterBattleState_Prefix(BattleUIController __instance)
	{
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Invalid comparison between Unknown and I4
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: 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_004d: 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_0093: Expected O, but got Unknown
		//IL_0194: 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)
		try
		{
			GameModeService service = ServiceLocator.GetService<GameModeService>();
			if (((service != null) ? service.CurrentGameMode : null) == null)
			{
				return true;
			}
			WinConditionPropagator winConditionPropagator = service.CurrentGameMode.WinConditionPropagator;
			if (winConditionPropagator == null)
			{
				return true;
			}
			List<TimeLimitWinCondition> list = new List<TimeLimitWinCondition>();
			Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
			foreach (Team val in allTeamsIncludingExtended)
			{
				WinCondition[] winConditionsForTeam = winConditionPropagator.GetWinConditionsForTeam(val);
				if (winConditionsForTeam == null)
				{
					continue;
				}
				WinCondition[] array = winConditionsForTeam;
				foreach (WinCondition val2 in array)
				{
					if (val2 != null && ((object)val2).GetType() == typeof(TimeLimitWinCondition))
					{
						list.Add((TimeLimitWinCondition)val2);
					}
				}
			}
			float num = float.MaxValue;
			int num2 = -1;
			for (int k = 0; k < list.Count; k++)
			{
				TimeLimitWinCondition val3 = list[k];
				if (val3.SecondsLeft < num)
				{
					num2 = k;
					num = val3.SecondsLeft;
				}
			}
			if (num2 == -1)
			{
				SetTimeLimitWinCondition(__instance, null);
				return false;
			}
			TimeLimitWinCondition val4 = list[num2];
			SetTimeLimitWinCondition(__instance, val4);
			FieldInfo? field = typeof(BattleUIController).GetField("m_winConditionTimerUi", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(BattleUIController).GetField("m_codeAnimation", BindingFlags.Instance | BindingFlags.NonPublic);
			object? obj = field?.GetValue(__instance);
			WinConditionTimerUI val5 = (WinConditionTimerUI)((obj is WinConditionTimerUI) ? obj : null);
			object obj2 = field2?.GetValue(__instance);
			if ((Object)(object)val5 != (Object)null && obj2 != null)
			{
				GlobalSettingsHandler service2 = ServiceLocator.GetService<GlobalSettingsHandler>();
				SettingsInstance val6 = ((service2 != null) ? service2.GetSettingsInstance("GAMEPLAY_FLIP_COLORS") : null);
				Team val7 = ((WinCondition)val4).OwningTeam;
				if (val6 != null)
				{
					int num3 = 0;
					try
					{
						PropertyInfo property = ((object)val6).GetType().GetProperty("currentValue");
						if (property != null)
						{
							num3 = (int)property.GetValue(val6);
						}
					}
					catch
					{
					}
					if ((int)val7 == 0)
					{
						val7 = (Team)((num3 != 0) ? 1 : 0);
					}
					else if ((int)val7 == 1)
					{
						val7 = (Team)(num3 == 0);
					}
				}
				val5.SetTeamText(val7);
				obj2.GetType().GetMethod("PlayIn")?.Invoke(obj2, null);
			}
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[BattleUIControllerPatches] OnEnterBattleState_Prefix 执行失败: " + ex.Message + "\n" + ex.StackTrace));
			return true;
		}
	}

	private static void SetTimeLimitWinCondition(BattleUIController instance, TimeLimitWinCondition value)
	{
		typeof(BattleUIController).GetField("m_timeLimitWinCondition", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(instance, value);
	}

	private static bool Update_Prefix(BattleUIController __instance)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			object? obj = typeof(BattleUIController).GetField("m_timeLimitWinCondition", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
			TimeLimitWinCondition val = (TimeLimitWinCondition)((obj is TimeLimitWinCondition) ? obj : null);
			if (val == null)
			{
				return true;
			}
			TeamSystem teamSystem = ((WinCondition)val).TeamSystem;
			List<Unit> list = ((teamSystem != null) ? teamSystem.GetWinConditionTeamUnits(((WinCondition)val).OwningTeam) : null);
			if (list != null && list.Count > 0)
			{
				return true;
			}
			SetTimeLimitWinCondition(__instance, null);
			object obj2 = typeof(BattleUIController).GetField("m_codeAnimation", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
			obj2?.GetType().GetMethod("PlayOut")?.Invoke(obj2, null);
			return false;
		}
		catch
		{
			return true;
		}
	}

	private static bool SetTeamText_Prefix(WinConditionTimerUI __instance, Team team)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		if (!TeamEnumExtension.IsExtendedTeam(team))
		{
			return true;
		}
		try
		{
			LocalizeText component = ((Component)__instance).GetComponent<LocalizeText>();
			if ((Object)(object)component == (Object)null)
			{
				return true;
			}
			component.Args = new string[1] { TeamEnumExtension.GetTeamName(team) };
			component.LocaleID = "WIN_CON_TEAM_WINS_IN";
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[BattleUIControllerPatches] SetTeamText_Prefix 执行失败: " + ex.Message));
			return true;
		}
	}
}
public static class ColorPickerLocalization
{
	public static bool IsChinese
	{
		get
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0035: Invalid comparison between Unknown and I4
			try
			{
				return typeof(Localizer).GetField("m_locale", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) is Language val && (int)val == 7;
			}
			catch
			{
				return false;
			}
		}
	}

	public static string GetOpacityText(int percent)
	{
		if (!IsChinese)
		{
			return $"Opacity: {percent}%";
		}
		return $"不透明度: {percent}%";
	}

	public static string GetEmissionText(int percent)
	{
		if (!IsChinese)
		{
			return $"Emission: {percent}%";
		}
		return $"发光度: {percent}%";
	}

	public static string GetSmoothnessText(int percent)
	{
		if (!IsChinese)
		{
			return $"Smoothness: {percent}%";
		}
		return $"平滑度: {percent}%";
	}
}
public class MaterialReplacerColorPicker : MonoBehaviour
{
	private Color m_currentColor = Color.white;

	private float m_currentHue;

	private float m_currentSaturation = 1f;

	private float m_currentBrightness = 1f;

	private float m_currentAlpha = 1f;

	private float m_currentEmission;

	private RectTransform m_colorPickerPanel;

	private Image m_colorSquare;

	private Image m_hueSlider;

	private Slider m_alphaSlider;

	private Slider m_emissionSlider;

	private Button m_closeButton;

	private TextMeshProUGUI m_alphaText;

	private TextMeshProUGUI m_emissionText;

	private bool m_isDraggingHue;

	private bool m_isDraggingColor;

	private RectTransform m_colorIndicator;

	private bool m_isColorPickerActive;

	private float m_currentSmoothness = 0.5f;

	private Slider m_smoothnessSlider;

	private TextMeshProUGUI m_smoothnessText;

	public float CurrentSmoothness => m_currentSmoothness;

	public event Action<Color, float, float> OnColorChanged;

	public event Action OnClosed;

	public static MaterialReplacerColorPicker Create()
	{
		//IL_000f: 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_001f: Invalid comparison between Unknown and I4
		//IL_0087: 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_009e: 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_0055: 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_0075: Unknown result type (might be due to invalid IL or missing references)
		Canvas val = null;
		Canvas[] array = Object.FindObjectsOfType<Canvas>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((int)array[i].renderMode == 0 || (int)array[i].renderMode == 1)
			{
				val = array[i];
				break;
			}
		}
		if ((Object)(object)val == (Object)null && array.Length != 0)
		{
			val = array[0];
		}
		if ((Object)(object)val == (Object)null)
		{
			GameObject val2 = new GameObject("ColorPickerCanvas");
			val = val2.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 9999;
			val2.AddComponent<CanvasScaler>();
			val2.AddComponent<GraphicRaycaster>();
			val2.AddComponent<EventSystem>();
		}
		GameObject val3 = new GameObject("MaterialReplacerColorPicker");
		val3.transform.SetParent(((Component)val).transform, false);
		MaterialReplacerColorPicker materialReplacerColorPicker = val3.AddComponent<MaterialReplacerColorPicker>();
		materialReplacerColorPicker.Initialize();
		val3.transform.SetAsLastSibling();
		return materialReplacerColorPicker;
	}

	private void Initialize()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00c6: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: 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_015c: Expected O, but got Unknown
		//IL_018a: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Expected O, but got Unknown
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Expected O, but got Unknown
		//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Unknown result type (might be due to invalid IL or missing references)
		//IL_0511: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_0564: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Expected O, but got Unknown
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Unknown result type (might be due to invalid IL or missing references)
		//IL_058b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0592: Unknown result type (might be due to invalid IL or missing references)
		//IL_059d: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
		m_colorPickerPanel = ((Component)this).gameObject.AddComponent<RectTransform>();
		m_colorPickerPanel.anchorMin = new Vector2(0.5f, 0.5f);
		m_colorPickerPanel.anchorMax = new Vector2(0.5f, 0.5f);
		m_colorPickerPanel.sizeDelta = new Vector2(400f, 500f);
		m_colorPickerPanel.anchoredPosition = Vector2.zero;
		((Graphic)((Component)this).gameObject.AddComponent<Image>()).color = new Color(0.2f, 0.2f, 0.2f, 0.95f);
		GameObject val = new GameObject("ColorSquare");
		val.transform.SetParent(((Component)this).transform, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		obj.anchorMin = new Vector2(0.05f, 0.3f);
		obj.anchorMax = new Vector2(0.65f, 0.9f);
		obj.offsetMin = Vector2.zero;
		obj.offsetMax = Vector2.zero;
		m_colorSquare = val.AddComponent<Image>();
		((Graphic)m_colorSquare).color = Color.white;
		m_colorSquare.type = (Type)0;
		EventTrigger trigger = val.AddComponent<EventTrigger>();
		AddEventTrigger(trigger, (EventTriggerType)2, OnColorSquarePointerDown);
		AddEventTrigger(trigger, (EventTriggerType)5, OnColorSquareDrag);
		GameObject val2 = new GameObject("ColorIndicator");
		val2.transform.SetParent(val.transform, false);
		m_colorIndicator = val2.AddComponent<RectTransform>();
		m_colorIndicator.sizeDelta = new Vector2(12f, 12f);
		m_colorIndicator.anchoredPosition = Vector2.zero;
		((Graphic)val2.AddComponent<Image>()).color = Color.white;
		GameObject val3 = new GameObject("Border");
		val3.transform.SetParent(val2.transform, false);
		RectTransform obj2 = val3.AddComponent<RectTransform>();
		obj2.anchorMin = Vector2.zero;
		obj2.anchorMax = Vector2.one;
		obj2.sizeDelta = new Vector2(2f, 2f);
		obj2.anchoredPosition = Vector2.zero;
		((Graphic)val3.AddComponent<Image>()).color = Color.black;
		GameObject val4 = new GameObject("HueSlider");
		val4.transform.SetParent(((Component)this).transform, false);
		RectTransform obj3 = val4.AddComponent<RectTransform>();
		obj3.anchorMin = new Vector2(0.7f, 0.3f);
		obj3.anchorMax = new Vector2(0.85f, 0.9f);
		obj3.offsetMin = Vector2.zero;
		obj3.offsetMax = Vector2.zero;
		m_hueSlider = val4.AddComponent<Image>();
		UpdateHueSliderTexture();
		UpdateColorSquare();
		UpdateColorIndicatorPosition();
		GameObject val5 = new GameObject("HueHandle");
		val5.transform.SetParent(val4.transform, false);
		RectTransform obj4 = val5.AddComponent<RectTransform>();
		obj4.anchorMin = new Vector2(0f, 0f);
		obj4.anchorMax = new Vector2(1f, 0f);
		obj4.sizeDelta = new Vector2(0f, 10f);
		obj4.anchoredPosition = Vector2.zero;
		((Graphic)val5.AddComponent<Image>()).color = Color.white;
		EventTrigger trigger2 = val4.AddComponent<EventTrigger>();
		AddEventTrigger(trigger2, (EventTriggerType)2, OnHueSliderPointerDown);
		AddEventTrigger(trigger2, (EventTriggerType)5, OnHueSliderDrag);
		CreateSlider("SmoothnessSlider", 0.05f, 0.2f, 0.65f, 0.25f, out m_smoothnessSlider, out m_smoothnessText, ColorPickerLocalization.GetSmoothnessText(50));
		m_smoothnessSlider.minValue = 0f;
		m_smoothnessSlider.maxValue = 1f;
		m_smoothnessSlider.value = m_currentSmoothness;
		((UnityEvent<float>)(object)m_smoothnessSlider.onValueChanged).AddListener((UnityAction<float>)OnSmoothnessChanged);
		CreateSlider("AlphaSlider", 0.05f, 0.15f, 0.65f, 0.2f, out m_alphaSlider, out m_alphaText, ColorPickerLocalization.GetOpacityText(100));
		m_alphaSlider.minValue = 0f;
		m_alphaSlider.maxValue = 1f;
		m_alphaSlider.value = 1f;
		((UnityEvent<float>)(object)m_alphaSlider.onValueChanged).AddListener((UnityAction<float>)OnAlphaChanged);
		CreateSlider("EmissionSlider", 0.05f, 0.05f, 0.65f, 0.1f, out m_emissionSlider, out m_emissionText, ColorPickerLocalization.GetEmissionText(0));
		m_emissionSlider.minValue = 0f;
		m_emissionSlider.maxValue = 2f;
		m_emissionSlider.value = 0f;
		((UnityEvent<float>)(object)m_emissionSlider.onValueChanged).AddListener((UnityAction<float>)OnEmissionChanged);
		GameObject val6 = new GameObject("CloseButton");
		val6.transform.SetParent(((Component)this).transform, false);
		RectTransform obj5 = val6.AddComponent<RectTransform>();
		obj5.anchorMin = new Vector2(0.9f, 0.9f);
		obj5.anchorMax = new Vector2(0.98f, 0.98f);
		obj5.offsetMin = Vector2.zero;
		obj5.offsetMax = Vector2.zero;
		m_closeButton = val6.AddComponent<Button>();
		((Graphic)val6.AddComponent<Image>()).color = new Color(0.8f, 0.2f, 0.2f);
		((UnityEvent)m_closeButton.onClick).AddListener(new UnityAction(Close));
		GameObject val7 = new GameObject("CloseText");
		val7.transform.SetParent(val6.transform, false);
		RectTransform obj6 = val7.AddComponent<RectTransform>();
		obj6.anchorMin = Vector2.zero;
		obj6.anchorMax = Vector2.one;
		obj6.offsetMin = Vector2.zero;
		obj6.offsetMax = Vector2.zero;
		TextMeshProUGUI obj7 = val7.AddComponent<TextMeshProUGUI>();
		((TMP_Text)obj7).text = "×";
		((TMP_Text)obj7).fontSize = 24f;
		((TMP_Text)obj7).alignment = (TextAlignmentOptions)514;
		((Graphic)obj7).color = Color.white;
	}

	private void CreateSlider(string name, float xMin, float yMin, float xMax, float yMax, out Slider slider, out TextMeshProUGUI label, string labelText)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: 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)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Expected O, but got Unknown
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: 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_0159: 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_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Expected O, but got Unknown
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name + "Label");
		val.transform.SetParent(((Component)this).transform, false);
		RectTransform obj = val.AddComponent<RectTransform>();
		obj.anchorMin = new Vector2(xMin, yMin);
		obj.anchorMax = new Vector2(xMax, yMin + 0.05f);
		obj.offsetMin = Vector2.zero;
		obj.offsetMax = Vector2.zero;
		label = val.AddComponent<TextMeshProUGUI>();
		((TMP_Text)label).text = labelText;
		((TMP_Text)label).fontSize = 14f;
		((Graphic)label).color = Color.white;
		GameObject val2 = new GameObject(name);
		val2.transform.SetParent(((Component)this).transform, false);
		RectTransform obj2 = val2.AddComponent<RectTransform>();
		obj2.anchorMin = new Vector2(xMin, yMin + 0.05f);
		obj2.anchorMax = new Vector2(xMax, yMax);
		obj2.offsetMin = Vector2.zero;
		obj2.offsetMax = Vector2.zero;
		((Graphic)val2.AddComponent<Image>()).color = new Color(0.3f, 0.3f, 0.3f);
		GameObject val3 = new GameObject("FillArea");
		val3.transform.SetParent(val2.transform, false);
		RectTransform obj3 = val3.AddComponent<RectTransform>();
		obj3.anchorMin = Vector2.zero;
		obj3.anchorMax = Vector2.one;
		obj3.offsetMin = Vector2.zero;
		obj3.offsetMax = Vector2.zero;
		GameObject val4 = new GameObject("Fill");
		val4.transform.SetParent(val3.transform, false);
		RectTransform val5 = val4.AddComponent<RectTransform>();
		val5.anchorMin = Vector2.zero;
		val5.anchorMax = new Vector2(0f, 1f);
		val5.offsetMin = Vector2.zero;
		val5.offsetMax = Vector2.zero;
		((Graphic)val4.AddComponent<Image>()).color = new Color(0.5f, 0.5f, 0.8f);
		GameObject val6 = new GameObject("HandleArea");
		val6.transform.SetParent(val2.transform, false);
		RectTransform obj4 = val6.AddComponent<RectTransform>();
		obj4.anchorMin = Vector2.zero;
		obj4.anchorMax = Vector2.one;
		obj4.offsetMin = Vector2.zero;
		obj4.offsetMax = Vector2.zero;
		GameObject val7 = new GameObject("Handle");
		val7.transform.SetParent(val6.transform, false);
		RectTransform val8 = val7.AddComponent<RectTransform>();
		val8.sizeDelta = new Vector2(20f, 20f);
		Image val9 = val7.AddComponent<Image>();
		((Graphic)val9).color = Color.white;
		slider = val2.AddComponent<Slider>();
		((Selectable)slider).targetGraphic = (Graphic)(object)val9;
		slider.handleRect = val8;
		slider.fillRect = val5;
		slider.direction = (Direction)0;
	}

	private void UpdateHueSliderTexture()
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)m_hueSlider == (Object)null)
		{
			return;
		}
		if ((Object)(object)m_hueSlider.sprite != (Object)null)
		{
			if ((Object)(object)m_hueSlider.sprite.texture != (Object)null)
			{
				Object.Destroy((Object)(object)m_hueSlider.sprite.texture);
			}
			Object.Destroy((Object)(object)m_hueSlider.sprite);
		}
		Texture2D val = new Texture2D(1, 256, (TextureFormat)4, false);
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		for (int i = 0; i < 256; i++)
		{
			val.SetPixel(0, i, Color.HSVToRGB((255f - (float)i) / 255f, 1f, 1f));
		}
		val.Apply();
		m_hueSlider.sprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 256f), new Vector2(0.5f, 0.5f), 100f);
	}

	private void UpdateColorSquare()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected O, but got Unknown
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)m_colorSquare == (Object)null)
		{
			return;
		}
		if ((Object)(object)m_colorSquare.sprite != (Object)null)
		{
			if ((Object)(object)m_colorSquare.sprite.texture != (Object)null)
			{
				Object.Destroy((Object)(object)m_colorSquare.sprite.texture);
			}
			Object.Destroy((Object)(object)m_colorSquare.sprite);
		}
		Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false);
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		for (int i = 0; i < 256; i++)
		{
			for (int j = 0; j < 256; j++)
			{
				val.SetPixel(i, j, Color.HSVToRGB(m_currentHue, (float)i / 255f, (float)j / 255f));
			}
		}
		val.Apply();
		m_colorSquare.sprite = Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
		m_colorSquare.type = (Type)0;
		m_colorSquare.preserveAspect = false;
	}

	private void OnColorSquarePointerDown(BaseEventData data)
	{
		m_isDraggingColor = true;
		UpdateColorFromSquarePosition(data);
	}

	private void OnColorSquareDrag(BaseEventData data)
	{
		if (m_isDraggingColor)
		{
			UpdateColorFromSquarePosition(data);
		}
	}

	private void UpdateColorFromSquarePosition(BaseEventData data)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		PointerEventData val = (PointerEventData)(object)((data is PointerEventData) ? data : null);
		if (val != null)
		{
			Vector2 val2 = default(Vector2);
			RectTransformUtility.ScreenPointToLocalPointInRectangle(((Graphic)m_colorSquare).rectTransform, val.position, val.pressEventCamera, ref val2);
			Rect rect = ((Graphic)m_colorSquare).rectTransform.rect;
			m_currentSaturation = Mathf.Clamp01((val2.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width);
			m_currentBrightness = Mathf.Clamp01((val2.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height);
			UpdateColorIndicatorPosition();
			UpdateColor();
		}
	}

	private void OnHueSliderPointerDown(BaseEventData data)
	{
		m_isDraggingHue = true;
		UpdateHueFromSliderPosition(data);
	}

	private void OnHueSliderDrag(BaseEventData data)
	{
		if (m_isDraggingHue)
		{
			UpdateHueFromSliderPosition(data);
		}
	}

	private void UpdateHueFromSliderPosition(BaseEventData data)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		PointerEventData val = (PointerEventData)(object)((data is PointerEventData) ? data : null);
		if (val == null)
		{
			return;
		}
		Vector2 val2 = default(Vector2);
		RectTransformUtility.ScreenPointToLocalPointInRectangle(((Graphic)m_hueSlider).rectTransform, val.position, val.pressEventCamera, ref val2);
		Rect rect = ((Graphic)m_hueSlider).rectTransform.rect;
		float num = Mathf.Clamp01((val2.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height);
		m_currentHue = 1f - num;
		if (((Component)m_hueSlider).transform.childCount > 0)
		{
			RectTransform component = ((Component)((Component)m_hueSlider).transform.GetChild(0)).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchorMin = new Vector2(0f, num);
				component.anchorMax = new Vector2(1f, num);
				component.anchoredPosition = Vector2.zero;
			}
		}
		UpdateColorSquare();
		UpdateColorIndicatorPosition();
		UpdateColor();
	}

	private void OnAlphaChanged(float value)
	{
		m_currentAlpha = value;
		((TMP_Text)m_alphaText).text = ColorPickerLocalization.GetOpacityText(Mathf.RoundToInt(value * 100f));
		UpdateColor();
	}

	private void OnEmissionChanged(float value)
	{
		m_currentEmission = value;
		((TMP_Text)m_emissionText).text = ColorPickerLocalization.GetEmissionText(Mathf.RoundToInt(value * 100f));
		UpdateColor();
	}

	private void UpdateColor()
	{
		//IL_0013: 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)
		m_currentColor = Color.HSVToRGB(m_currentHue, m_currentSaturation, m_currentBrightness);
		this.OnColorChanged?.Invoke(m_currentColor, m_currentAlpha, m_currentEmission);
	}

	public void SetColor(Color color, float alpha, float emission)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		m_currentAlpha = alpha;
		m_currentEmission = emission;
		Color.RGBToHSV(color, ref m_currentHue, ref m_currentSaturation, ref m_currentBrightness);
		m_alphaSlider.value = alpha;
		m_emissionSlider.value = emission;
		((TMP_Text)m_alphaText).text = ColorPickerLocalization.GetOpacityText(Mathf.RoundToInt(alpha * 100f));
		((TMP_Text)m_emissionText).text = ColorPickerLocalization.GetEmissionText(Mathf.RoundToInt(emission * 100f));
		if ((Object)(object)m_smoothnessSlider != (Object)null)
		{
			m_smoothnessSlider.SetValueWithoutNotify(m_currentSmoothness);
		}
		if ((Object)(object)m_smoothnessText != (Object)null)
		{
			((TMP_Text)m_smoothnessText).text = ColorPickerLocalization.GetSmoothnessText(Mathf.RoundToInt(m_currentSmoothness * 100f));
		}
		if ((Object)(object)m_hueSlider != (Object)null && ((Component)m_hueSlider).transform.childCount > 0)
		{
			RectTransform component = ((Component)((Component)m_hueSlider).transform.GetChild(0)).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				float num = 1f - m_currentHue;
				component.anchorMin = new Vector2(0f, num);
				component.anchorMax = new Vector2(1f, num);
				component.anchoredPosition = Vector2.zero;
			}
		}
		UpdateColorSquare();
		UpdateColorIndicatorPosition();
	}

	public void Close()
	{
		this.OnClosed?.Invoke();
	}

	private void AddEventTrigger(EventTrigger trigger, EventTriggerType type, UnityAction<BaseEventData> action)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		Entry val = new Entry();
		val.eventID = type;
		((UnityEvent<BaseEventData>)(object)val.callback).AddListener(action);
		trigger.triggers.Add(val);
	}

	private void Update()
	{
		if (((Component)this).gameObject.activeSelf)
		{
			if (Input.GetMouseButtonUp(0))
			{
				m_isDraggingColor = false;
				m_isDraggingHue = false;
			}
			if (m_isColorPickerActive && (Object)(object)DMEditor.Instance != (Object)null)
			{
				DMEditor.Instance.ShowCursor();
				DMEditor.Instance.UpdateCursor();
			}
		}
	}

	private void UpdateColorIndicatorPosition()
	{
		//IL_0028: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)m_colorIndicator == (Object)null) && !((Object)(object)m_colorSquare == (Object)null))
		{
			Rect rect = ((Graphic)m_colorSquare).rectTransform.rect;
			float num = ((Rect)(ref rect)).xMin + m_currentSaturation * ((Rect)(ref rect)).width;
			float num2 = ((Rect)(ref rect)).yMin + m_currentBrightness * ((Rect)(ref rect)).height;
			m_colorIndicator.anchoredPosition = new Vector2(num, num2);
		}
	}

	public void SetActive(bool active)
	{
		m_isColorPickerActive = active;
		if ((Object)(object)DMEditor.Instance != (Object)null)
		{
			if (active)
			{
				((Component)this).gameObject.SetActive(true);
				return;
			}
			DMEditor.Instance.HideCursor();
			((Component)this).gameObject.SetActive(false);
		}
		else
		{
			((Component)this).gameObject.SetActive(active);
		}
	}

	private void OnSmoothnessChanged(float value)
	{
		m_currentSmoothness = value;
		if ((Object)(object)m_smoothnessText != (Object)null)
		{
			((TMP_Text)m_smoothnessText).text = ColorPickerLocalization.GetSmoothnessText(Mathf.RoundToInt(m_currentSmoothness * 100f));
		}
		UpdateColor();
	}

	public void SetSmoothness(float smoothness)
	{
		m_currentSmoothness = Mathf.Clamp01(smoothness);
		if ((Object)(object)m_smoothnessSlider != (Object)null)
		{
			m_smoothnessSlider.SetValueWithoutNotify(m_currentSmoothness);
		}
		if ((Object)(object)m_smoothnessText != (Object)null)
		{
			((TMP_Text)m_smoothnessText).text = ColorPickerLocalization.GetSmoothnessText(Mathf.RoundToInt(m_currentSmoothness * 100f));
		}
	}
}
internal static class MultiTeamAIPatches
{
	private static FieldInfo s_barrierField;

	private static FieldInfo s_filterField;

	private static FieldInfo s_targetFilterField;

	private static PropertyInfo s_componentGroupsProperty;

	private static FieldInfo s_groupIndexField;

	private static FieldInfo s_targetGroupIndexField;

	private static PropertyInfo s_entityManagerProperty;

	private static bool s_reflectionCacheInitialized = false;

	private static GameStateManager s_gameStateManager = null;

	private static GameState s_currentGameState = (GameState)(-1);

	private static Team[] s_cachedAllTeams = null;

	private static int s_lastBattleTeamCount = 0;

	private const int FFA_TEAM_COUNT_THRESHOLD = 50;

	private static Dictionary<Entity, BeingTargetedBy> s_initialBeingTargetedByValues = new Dictionary<Entity, BeingTargetedBy>();

	private static void InitializeReflectionCache()
	{
		if (s_reflectionCacheInitialized)
		{
			return;
		}
		try
		{
			s_barrierField = typeof(FindEnemyTargetSystem).GetField("m_barrier", BindingFlags.Instance | BindingFlags.NonPublic);
			s_filterField = typeof(FindEnemyTargetSystem).GetField("m_filter", BindingFlags.Instance | BindingFlags.NonPublic);
			s_targetFilterField = typeof(FindEnemyTargetSystem).GetField("m_targetFilter", BindingFlags.Instance | BindingFlags.NonPublic);
			s_componentGroupsProperty = typeof(FindEnemyTargetSystem).GetProperty("ComponentGroups", BindingFlags.Instance | BindingFlags.Public);
			Type baseType = typeof(FindEnemyTargetSystem).BaseType;
			if (baseType != null)
			{
				s_entityManagerProperty = baseType.GetProperty("EntityManager", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			if (s_filterField != null)
			{
				s_groupIndexField = s_filterField.FieldType.GetField("GroupIndex", BindingFlags.Instance | BindingFlags.Public);
			}
			if (s_targetFilterField != null)
			{
				s_targetGroupIndexField = s_targetFilterField.FieldType.GetField("GroupIndex", BindingFlags.Instance | BindingFlags.Public);
			}
			s_reflectionCacheInitialized = true;
			Debug.Log((object)"[MultiTeamAIPatches] 反射缓存初始化完成");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] 反射缓存初始化失败: " + ex.Message));
		}
	}

	private static void InitializeGameStateManager()
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		if (s_gameStateManager != null)
		{
			return;
		}
		try
		{
			Type type = typeof(FindEnemyTargetSystem).Assembly.GetType("ServiceLocator");
			if (!(type != null))
			{
				return;
			}
			MethodInfo method = type.GetMethod("GetService", BindingFlags.Static | BindingFlags.Public);
			if (!(method != null))
			{
				return;
			}
			Type type2 = typeof(FindEnemyTargetSystem).Assembly.GetType("Landfall.TABS.GameState.GameStateManager");
			if (!(type2 != null))
			{
				return;
			}
			object obj = method.MakeGenericMethod(type2).Invoke(null, null);
			if (obj != null)
			{
				s_gameStateManager = (GameStateManager)((obj is GameStateManager) ? obj : null);
				if (s_gameStateManager != null)
				{
					s_gameStateManager.GameStateChanged += OnGameStateChanged;
					s_currentGameState = s_gameStateManager.GameState;
					Debug.Log((object)$"[MultiTeamAIPatches] 游戏状态管理器初始化完成,当前状态: {s_currentGameState}");
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[MultiTeamAIPatches] 初始化游戏状态管理器失败: " + ex.Message));
		}
	}

	private static void OnGameStateChanged(GameState newState)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((int)s_currentGameState != 1 && (int)newState == 1)
			{
				s_cachedAllTeams = null;
				Team[] allTeamsCached = GetAllTeamsCached();
				s_lastBattleTeamCount = allTeamsCached.Length;
				Debug.Log((object)$"[MultiTeamAIPatches] 战斗开始 - 队伍数: {allTeamsCached.Length}");
			}
			s_currentGameState = newState;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] 游戏状态变化处理失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static Team[] GetAllTeamsCached()
	{
		if (s_cachedAllTeams == null)
		{
			s_cachedAllTeams = TeamEnumExtension.GetAllTeamsIncludingExtended();
		}
		return s_cachedAllTeams;
	}

	private static bool IsInBattleState()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Invalid comparison between Unknown and I4
		if (s_gameStateManager == null)
		{
			InitializeGameStateManager();
			if (s_gameStateManager == null)
			{
				return false;
			}
		}
		return (int)s_currentGameState == 1;
	}

	public static void ApplyPatches()
	{
		//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_001f: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_003c: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[MultiTeamAIPatches] 正在应用多队伍AI系统补丁...");
			InitializeReflectionCache();
			Harmony val = new Harmony("Mod_Name.MultiTeamAI");
			PatchFindEnemyTargetSystem(val);
			PatchFindFriendlyHighestPriceTargetSystem(val);
			PatchFindFriendlyTargetSystem(val);
			PatchFindNearestFriendTargetSystem(val);
			PatchCheckClosestUnitTargets(val);
			PatchTeamSystemTriggerUnitDeathAction(val);
			Debug.Log((object)"[MultiTeamAIPatches] 多队伍AI系统补丁应用完成!");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] 应用补丁时发生错误: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void PatchFindEnemyTargetSystem(Harmony harmony)
	{
		//IL_0038: 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_0060: Expected O, but got Unknown
		//IL_0060: Expected O, but got Unknown
		MethodInfo method = typeof(FindEnemyTargetSystem).GetMethod("OnUpdate", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamAIPatches).GetMethod("FindEnemyTargetSystem_OnUpdate_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), new HarmonyMethod(typeof(MultiTeamAIPatches).GetMethod("FindEnemyTargetSystem_OnUpdate_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Debug.Log((object)"[MultiTeamAIPatches] FindEnemyTargetSystem补丁已应用(使用前缀和后缀补丁)");
		}
		else
		{
			Debug.LogWarning((object)"[MultiTeamAIPatches] 无法找到FindEnemyTargetSystem.OnUpdate方法");
		}
	}

	private static void FindEnemyTargetSystem_OnUpdate_Prefix(FindEnemyTargetSystem __instance)
	{
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: 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_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: 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_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Expected I4, but got Unknown
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			s_initialBeingTargetedByValues.Clear();
			EntityManager val = null;
			bool flag = false;
			if (s_entityManagerProperty != null)
			{
				try
				{
					object value = s_entityManagerProperty.GetValue(__instance);
					if (value != null)
					{
						val = (EntityManager)value;
						flag = true;
					}
				}
				catch
				{
				}
			}
			if (!flag)
			{
				return;
			}
			Team[] allTeamsCached = GetAllTeamsCached();
			if (allTeamsCached == null || allTeamsCached.Length == 0)
			{
				return;
			}
			PropertyInfo property = typeof(FindEnemyTargetSystem).GetProperty("ComponentGroups", BindingFlags.Instance | BindingFlags.Public);
			if (property == null)
			{
				return;
			}
			ComponentGroup[] array = (ComponentGroup[])property.GetValue(__instance);
			if (array == null)
			{
				return;
			}
			FieldInfo field = typeof(FindEnemyTargetSystem).GetField("m_targetFilter", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return;
			}
			object value2 = field.GetValue(__instance);
			if (value2 == null)
			{
				return;
			}
			FieldInfo field2 = value2.GetType().GetField("GroupIndex", BindingFlags.Instance | BindingFlags.Public);
			if (field2 == null)
			{
				return;
			}
			int num = (int)field2.GetValue(value2);
			if (num < 0 || num >= array.Length)
			{
				return;
			}
			ComponentGroup val2 = array[num];
			if (val2 == null)
			{
				return;
			}
			if (allTeamsCached.Length > 50)
			{
				val2.ResetFilter();
				EntityArray entityArray = val2.GetEntityArray();
				for (int i = 0; i < ((EntityArray)(ref entityArray)).Length; i++)
				{
					Entity val3 = ((EntityArray)(ref entityArray))[i];
					if (s_initialBeingTargetedByValues.ContainsKey(val3))
					{
						continue;
					}
					BeingTargetedBy value3 = new BeingTargetedBy
					{
						Value = 0f
					};
					try
					{
						if (val.HasComponent<BeingTargetedBy>(val3))
						{
							value3 = val.GetComponentData<BeingTargetedBy>(val3);
						}
					}
					catch
					{
					}
					s_initialBeingTargetedByValues[val3] = value3;
				}
				val2.ResetFilter();
				return;
			}
			foreach (Team val4 in allTeamsCached)
			{
				val2.ResetFilter();
				val2.SetFilter<Team>(new Team
				{
					Value = (int)val4
				});
				EntityArray entityArray2 = val2.GetEntityArray();
				for (int k = 0; k < ((EntityArray)(ref entityArray2)).Length; k++)
				{
					Entity val5 = ((EntityArray)(ref entityArray2))[k];
					if (s_initialBeingTargetedByValues.ContainsKey(val5))
					{
						continue;
					}
					BeingTargetedBy value4 = new BeingTargetedBy
					{
						Value = 0f
					};
					try
					{
						if (val.HasComponent<BeingTargetedBy>(val5))
						{
							value4 = val.GetComponentData<BeingTargetedBy>(val5);
						}
					}
					catch
					{
					}
					s_initialBeingTargetedByValues[val5] = value4;
				}
				val2.ResetFilter();
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] FindEnemyTargetSystem前缀补丁执行失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void FindEnemyTargetSystem_OnUpdate_Postfix(FindEnemyTargetSystem __instance, ref JobHandle __result, JobHandle inputDeps)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: 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_028f: 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_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Expected I4, but got Unknown
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b5: 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_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0358: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0374: Expected I4, but got Unknown
		//IL_0374: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0406: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((JobHandle)(ref __result)).IsCompleted)
			{
				((JobHandle)(ref __result)).Complete();
			}
			EntityManager val = null;
			bool flag = false;
			if (s_entityManagerProperty != null)
			{
				try
				{
					object value = s_entityManagerProperty.GetValue(__instance);
					if (value != null)
					{
						val = (EntityManager)value;
						flag = true;
					}
				}
				catch
				{
				}
			}
			if (s_gameStateManager == null)
			{
				InitializeGameStateManager();
			}
			Team[] allTeamsCached = GetAllTeamsCached();
			if (allTeamsCached == null || allTeamsCached.Length <= 2)
			{
				return;
			}
			if (!s_reflectionCacheInitialized || s_barrierField == null || s_filterField == null || s_targetFilterField == null || s_componentGroupsProperty == null || s_groupIndexField == null || s_targetGroupIndexField == null)
			{
				Debug.LogWarning((object)"[MultiTeamAIPatches] 反射缓存未初始化或缺失,尝试重新初始化");
				InitializeReflectionCache();
				if (!s_reflectionCacheInitialized)
				{
					return;
				}
			}
			ComponentDataFromEntity<HasTargetTag> componentDataFromEntity = ((ComponentSystemBase)__instance).GetComponentDataFromEntity<HasTargetTag>(true);
			ComponentDataFromEntity<IsTarget> componentDataFromEntity2 = ((ComponentSystemBase)__instance).GetComponentDataFromEntity<IsTarget>(true);
			object value2 = s_barrierField.GetValue(__instance);
			if (value2 == null)
			{
				return;
			}
			MethodInfo method = value2.GetType().GetMethod("CreateCommandBuffer");
			if (method == null)
			{
				return;
			}
			EntityCommandBuffer entityCommandBuffer = (EntityCommandBuffer)method.Invoke(value2, null);
			ComponentGroup[] array = (ComponentGroup[])s_componentGroupsProperty.GetValue(__instance);
			if (array == null)
			{
				return;
			}
			object value3 = s_filterField.GetValue(__instance);
			object value4 = s_targetFilterField.GetValue(__instance);
			if (value3 == null || value4 == null)
			{
				return;
			}
			int num = (int)s_groupIndexField.GetValue(value3);
			int num2 = (int)s_targetGroupIndexField.GetValue(value4);
			if (num < 0 || num >= array.Length || num2 < 0 || num2 >= array.Length)
			{
				return;
			}
			ComponentGroup val2 = array[num];
			ComponentGroup val3 = array[num2];
			if (val2 == null || val3 == null)
			{
				return;
			}
			JobHandle val4 = __result;
			Dictionary<Entity, BeingTargetedBy> dictionary = new Dictionary<Entity, BeingTargetedBy>(s_initialBeingTargetedByValues);
			Dictionary<Entity, float> dictionary2 = new Dictionary<Entity, float>();
			if (allTeamsCached.Length > 50)
			{
				ProcessAllUnitsFFA(val2, val3, entityCommandBuffer, dictionary, componentDataFromEntity, flag, val);
				__result = val4;
				return;
			}
			foreach (Team val5 in allTeamsCached)
			{
				val2.ResetFilter();
				val2.SetFilter<Team>(new Team
				{
					Value = (int)val5
				});
				EntityArray entityArray = val2.GetEntityArray();
				for (int j = 0; j < ((EntityArray)(ref entityArray)).Length; j++)
				{
					Entity val6 = ((EntityArray)(ref entityArray))[j];
					if (!componentDataFromEntity.Exists(val6))
					{
						continue;
					}
					HasTargetTag val7 = componentDataFromEntity[val6];
					if (((Entity)(ref val7.Target)).Equals(Entity.Null))
					{
						continue;
					}
					((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<HasTargetTag>(val6, new HasTargetTag
					{
						Target = Entity.Null
					});
					if (!flag)
					{
						continue;
					}
					try
					{
						if (val.Exists(val7.Target) && val.HasComponent<IsTarget>(val7.Target))
						{
							((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<IsTarget>(val7.Target, new IsTarget
							{
								Targetee = Entity.Null
							});
						}
					}
					catch
					{
					}
				}
				val2.ResetFilter();
			}
			foreach (Team attackerTeam in allTeamsCached)
			{
				ProcessAttackerTeamAgainstAllEnemies(__instance, val2, val3, attackerTeam, allTeamsCached, componentDataFromEntity, componentDataFromEntity2, entityCommandBuffer, dictionary, dictionary2, flag, val);
			}
			Dictionary<Entity, BeingTargetedBy> dictionary3 = new Dictionary<Entity, BeingTargetedBy>();
			foreach (Team val8 in allTeamsCached)
			{
				val3.ResetFilter();
				val3.SetFilter<Team>(new Team
				{
					Value = (int)val8
				});
				EntityArray entityArray2 = val3.GetEntityArray();
				if (((EntityArray)(ref entityArray2)).Length > 0)
				{
					ComponentDataArray<BeingTargetedBy> componentDataArray = val3.GetComponentDataArray<BeingTargetedBy>();
					for (int m = 0; m < ((EntityArray)(ref entityArray2)).Length; m++)
					{
						Entity key = ((EntityArray)(ref entityArray2))[m];
						if (!dictionary3.ContainsKey(key))
						{
							if (m < componentDataArray.Length)
							{
								dictionary3[key] = componentDataArray[m];
								continue;
							}
							BeingTargetedBy val9 = (BeingTargetedBy)(dictionary.ContainsKey(key) ? dictionary[key] : new BeingTargetedBy
							{
								Value = 0f
							});
							float num3 = (dictionary2.ContainsKey(key) ? dictionary2[key] : 0f);
							dictionary3[key] = new BeingTargetedBy
							{
								Value = val9.Value + num3
							};
						}
					}
				}
				val3.ResetFilter();
			}
			foreach (KeyValuePair<Entity, BeingTargetedBy> item in dictionary3)
			{
				((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<BeingTargetedBy>(item.Key, item.Value);
			}
			__result = val4;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] FindEnemyTargetSystem补丁执行失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void ProcessAllUnitsFFA(ComponentGroup unitGroup, ComponentGroup targetGroup, EntityCommandBuffer entityCommandBuffer, Dictionary<Entity, BeingTargetedBy> initialBeingTargetedBy, ComponentDataFromEntity<HasTargetTag> hasTargetTag, bool hasEntityManager, EntityManager entityManager)
	{
		//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_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_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			unitGroup.ResetFilter();
			targetGroup.ResetFilter();
			EntityArray entityArray = unitGroup.GetEntityArray();
			EntityArray entityArray2 = targetGroup.GetEntityArray();
			if (((EntityArray)(ref entityArray)).Length == 0 || ((EntityArray)(ref entityArray2)).Length == 0)
			{
				unitGroup.ResetFilter();
				targetGroup.ResetFilter();
				return;
			}
			for (int i = 0; i < ((EntityArray)(ref entityArray)).Length; i++)
			{
				Entity val = ((EntityArray)(ref entityArray))[i];
				if (!hasTargetTag.Exists(val))
				{
					continue;
				}
				HasTargetTag val2 = hasTargetTag[val];
				if (((Entity)(ref val2.Target)).Equals(Entity.Null))
				{
					continue;
				}
				((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<HasTargetTag>(val, new HasTargetTag
				{
					Target = Entity.Null
				});
				if (!hasEntityManager)
				{
					continue;
				}
				try
				{
					if (entityManager.Exists(val2.Target) && entityManager.HasComponent<IsTarget>(val2.Target))
					{
						((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<IsTarget>(val2.Target, new IsTarget
						{
							Targetee = Entity.Null
						});
					}
				}
				catch
				{
				}
			}
			SharedComponentDataArray<Team> sharedComponentDataArray = unitGroup.GetSharedComponentDataArray<Team>();
			ComponentDataArray<Range> componentDataArray = unitGroup.GetComponentDataArray<Range>();
			ComponentDataArray<PredictedPosition> componentDataArray2 = unitGroup.GetComponentDataArray<PredictedPosition>();
			SharedComponentDataArray<Team> sharedComponentDataArray2 = targetGroup.GetSharedComponentDataArray<Team>();
			ComponentDataArray<HipPosition> componentDataArray3 = targetGroup.GetComponentDataArray<HipPosition>();
			ComponentDataArray<TargetPriority> componentDataArray4 = targetGroup.GetComponentDataArray<TargetPriority>();
			targetGroup.GetComponentDataArray<TargetThickness>();
			float[] array = new float[((EntityArray)(ref entityArray2)).Length];
			for (int j = 0; j < ((EntityArray)(ref entityArray2)).Length; j++)
			{
				Entity key = ((EntityArray)(ref entityArray2))[j];
				array[j] = (initialBeingTargetedBy.ContainsKey(key) ? initialBeingTargetedBy[key].Value : 0f);
			}
			for (int k = 0; k < ((EntityArray)(ref entityArray)).Length; k++)
			{
				int value = sharedComponentDataArray[k].Value;
				float attackRange = componentDataArray[k].AttackRange;
				float3 value2 = componentDataArray2[k].Value;
				int num = -1;
				float num2 = float.MinValue;
				for (int l = 0; l < ((EntityArray)(ref entityArray2)).Length; l++)
				{
					if (sharedComponentDataArray2[l].Value != value)
					{
						float num3 = math.length(componentDataArray3[l].Value - value2);
						float num4 = ((componentDataArray4[l].Value > 0f) ? componentDataArray4[l].Value : 1f);
						float num5 = (0f - num3) / num4 - array[l] * attackRange * 0.05f;
						if (num5 > num2)
						{
							num2 = num5;
							num = l;
						}
					}
				}
				((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<AttackThickness>(((EntityArray)(ref entityArray))[k], new AttackThickness
				{
					Value = 0f
				});
				if (num >= 0)
				{
					Entity target = ((EntityArray)(ref entityArray2))[num];
					((EntityCommandBuffer)(ref entityCommandBuffer)).SetComponent<HasTargetTag>(((EntityArray)(ref entityArray))[k], new H