Decompiled source of Foreign forces v1.0.1

Foreign_forces.dll

Decompiled 15 hours 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.InteropServices;
using System.Runtime.Serialization;
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.UnitPlacement;
using Landfall.TABS.WinConditions;
using Landfall.TABS.Workshop;
using LevelCreator;
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.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Mod name")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("made in SFT by FhpSlime")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3a45c3cf-230c-4310-952f-0887d4266a22")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MT;

internal static class TeamEnumExtension
{
	public const int TeamGreen = 2;

	public const int TeamYellow = 3;

	public const int TeamPurple = 4;

	public const int TeamOrange = 5;

	private static readonly string[] TeamNames = new string[6] { "Red", "Blue", "Green", "Yellow", "Purple", "Orange" };

	private static HashSet<Team> s_dynamicTeams = new HashSet<Team>();

	private static Dictionary<Team, string> s_dynamicTeamNames = new Dictionary<Team, string>();

	private static Team[] s_cachedAllTeams = null;

	public static void Initialize()
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"[TeamEnumExtension] 初始化Team枚举扩展...");
		Team[] values = Enum.GetValues(typeof(Team)).Cast<Team>().ToArray();
		Debug.Log((object)("[TeamEnumExtension] 当前Team枚举值: " + string.Join(", ", values)));
		MultiTeamPatches.RegisterTeamColor((Team)2, new Color(0.2f, 0.8f, 0.2f, 1f));
		MultiTeamPatches.RegisterTeamColor((Team)3, new Color(1f, 0.9f, 0.2f, 1f));
		MultiTeamPatches.RegisterTeamColor((Team)4, new Color(0.6f, 0.2f, 0.8f, 1f));
		MultiTeamPatches.RegisterTeamColor((Team)5, new Color(1f, 0.5f, 0.2f, 1f));
		Debug.Log((object)"[TeamEnumExtension] Team枚举扩展初始化完成");
	}

	public static Team IntToTeam(int value)
	{
		if (!Enum.IsDefined(typeof(Team), value))
		{
			if (value >= 0 && value < TeamNames.Length)
			{
				return (Team)value;
			}
			Debug.LogWarning((object)$"[TeamEnumExtension] 无效的队伍值: {value},返回Red");
			return (Team)0;
		}
		return (Team)value;
	}

	public static string GetTeamName(Team team)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Expected I4, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		int num = (int)team;
		if (num >= 0 && num < TeamNames.Length)
		{
			return TeamNames[num];
		}
		if (s_dynamicTeamNames.ContainsKey(team))
		{
			return s_dynamicTeamNames[team];
		}
		return $"Team_{num}";
	}

	public static bool IsExtendedTeam(Team team)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		if ((int)team != 0)
		{
			return (int)team != 1;
		}
		return false;
	}

	public static Team[] GetAllTeamsIncludingExtended()
	{
		if (s_cachedAllTeams != null)
		{
			return s_cachedAllTeams;
		}
		List<Team> list = new List<Team>();
		list.Add((Team)0);
		list.Add((Team)1);
		list.Add((Team)2);
		list.Add((Team)3);
		list.Add((Team)4);
		list.Add((Team)5);
		list.AddRange(s_dynamicTeams);
		s_cachedAllTeams = list.ToArray();
		return s_cachedAllTeams;
	}

	public static void RegisterDynamicTeam(Team team, string teamName)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		bool num = !s_dynamicTeams.Contains(team);
		if (num)
		{
			s_dynamicTeams.Add(team);
			s_dynamicTeamNames[team] = teamName;
			Debug.Log((object)$"[TeamEnumExtension] 已注册动态队伍: {teamName} (Team: {team})");
		}
		else
		{
			s_dynamicTeamNames[team] = teamName;
			Debug.Log((object)$"[TeamEnumExtension] 已更新动态队伍名称: {teamName} (Team: {team})");
		}
		if (num)
		{
			ClearCachedTeams();
		}
	}

	public static bool IsDynamicTeam(Team team)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		return s_dynamicTeams.Contains(team);
	}

	public static Team[] GetDynamicTeams()
	{
		return s_dynamicTeams.ToArray();
	}

	public static void ClearCachedTeams()
	{
		s_cachedAllTeams = null;
	}
}
public static class MultiTeamUsageExample
{
	public static void Example1_CreateUnitWithExtendedTeam()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		string teamName = TeamEnumExtension.GetTeamName((Team)2);
		Debug.Log((object)("创建队伍: " + teamName));
		Color teamColor = MultiTeamPatches.GetTeamColor((Team)2);
		Debug.Log((object)$"队伍颜色: {teamColor}");
	}

	public static void Example2_SwitchBetweenTeams()
	{
		//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_0020: Unknown result type (might be due to invalid IL or missing references)
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		for (int i = 0; i < allTeamsIncludingExtended.Length; i++)
		{
			int num = (int)allTeamsIncludingExtended[i];
			string teamName = TeamEnumExtension.GetTeamName((Team)num);
			Color teamColor = MultiTeamPatches.GetTeamColor((Team)num);
			Debug.Log((object)$"队伍: {teamName}, 颜色: {teamColor}");
		}
	}

	public static void Example3_CheckTeamType(Team team)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (TeamEnumExtension.IsExtendedTeam(team))
		{
			Debug.Log((object)$"{team} 是扩展队伍");
		}
		else
		{
			Debug.Log((object)$"{team} 是原始队伍(Red或Blue)");
		}
		if (MultiTeamPatches.IsValidTeam(team))
		{
			Debug.Log((object)$"{team} 是有效队伍");
		}
	}

	public static void Example4_RegisterCustomTeamColor()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		int num = 6;
		Color val = default(Color);
		((Color)(ref val))..ctor(0f, 1f, 1f, 1f);
		MultiTeamPatches.RegisterTeamColor((Team)num, val);
		Debug.Log((object)$"已注册自定义队伍 {num} 的颜色: {val}");
	}

	public static void Example5_UseExtendedTeamInTeamHolder(TeamHolder teamHolder)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)teamHolder == (Object)null))
		{
			teamHolder.team = (Team)2;
			teamHolder.SwitchTeam();
			Debug.Log((object)$"当前队伍: {teamHolder.team}");
		}
	}

	public static void Example6_GetOtherTeam()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		Team val = (Team)0;
		Team otherTeam = TeamUtlity.GetOtherTeam(val);
		Debug.Log((object)$"当前队伍: {val}, 其他队伍: {otherTeam}");
		Team val2 = (Team)2;
		Team otherTeam2 = TeamUtlity.GetOtherTeam(val2);
		Debug.Log((object)$"当前队伍: {val2}, 下一个队伍: {otherTeam2}");
	}

	public static void Example7_UseExtendedTeamInBudget()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		Team val = (Team)2;
		Debug.Log((object)$"使用扩展队伍进行预算操作: {val}");
	}

	public static void Example8_IterateAllTeams()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		foreach (Team val in allTeamsIncludingExtended)
		{
			string teamName = TeamEnumExtension.GetTeamName(val);
			Color teamColor = MultiTeamPatches.GetTeamColor(val);
			Debug.Log((object)$"队伍: {teamName} ({val}), 颜色: {teamColor}");
		}
		Team[] array = Enum.GetValues(typeof(Team)).Cast<Team>().ToArray();
		Debug.Log((object)$"标准队伍数量: {array.Length}");
		Team[] array2 = new Team[6];
		RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		Team[] array3 = (Team[])(object)array2;
		Debug.Log((object)$"手动定义队伍数量: {array3.Length}");
	}
}
internal static class MultiTeamPatches
{
	public const int TeamGreen = 2;

	public const int TeamYellow = 3;

	public const int TeamPurple = 4;

	public const int TeamOrange = 5;

	private static Dictionary<Team, Color> s_teamColors = new Dictionary<Team, Color>
	{
		{
			(Team)0,
			new Color(14f / 15f, 22f / 51f, 0.4f, 1f)
		},
		{
			(Team)1,
			new Color(59f / 85f, 0.77254903f, 1f, 1f)
		},
		{
			(Team)2,
			new Color(0.2f, 0.8f, 0.2f, 1f)
		},
		{
			(Team)3,
			new Color(1f, 0.9f, 0.2f, 1f)
		},
		{
			(Team)4,
			new Color(0.6f, 0.2f, 0.8f, 1f)
		},
		{
			(Team)5,
			new Color(1f, 0.5f, 0.2f, 1f)
		}
	};

	private static Dictionary<Type, Dictionary<Team, MonoBehaviour>> s_teamInstances = new Dictionary<Type, Dictionary<Team, MonoBehaviour>>();

	private static Dictionary<int, Dictionary<Team, Material>> s_paletteTeamMaterials = new Dictionary<int, Dictionary<Team, Material>>();

	private static Dictionary<int, Dictionary<Team, Material>> s_teamColorMaterials = new Dictionary<int, Dictionary<Team, Material>>();

	private static Dictionary<Team, float> s_teamAlphas = new Dictionary<Team, float>();

	private static Dictionary<Team, float> s_teamEmissions = new Dictionary<Team, float>();

	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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_003d: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[MultiTeamPatches] 正在应用多队伍系统补丁...");
			Harmony val = new Harmony("Mod_Name.MultiTeam");
			PatchTeamColorPaletteData(val);
			PatchTeamColor(val);
			PatchTeamSingletons(val);
			PatchTeamHolder(val);
			PatchTeamUtlity(val);
			PatchWinCondition(val);
			PatchTABCUnitUI(val);
			MultiTeamInputPatches.ApplyPatches();
			BattleBudgetPatches.ApplyPatches();
			Debug.Log((object)"[MultiTeamPatches] 多队伍系统补丁应用完成!");
			Debug.Log((object)$"[MultiTeamPatches] 当前支持队伍数: {Enum.GetValues(typeof(Team)).Length}");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamPatches] 应用补丁时发生错误: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void PatchTeamColorPaletteData(Harmony harmony)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		MethodInfo method = typeof(TeamColorPaletteData).GetMethod("GetColor");
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamColorPaletteData_GetColor_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method2 = typeof(TeamColorPaletteData).GetMethod("GetMaterial");
		if (method2 != null)
		{
			harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamColorPaletteData_GetMaterial_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool TeamColorPaletteData_GetColor_Prefix(TeamColorPaletteData __instance, Team team, ref Color __result)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if ((int)team == 0 || (int)team == 1)
		{
			return true;
		}
		if (s_teamColors.ContainsKey(team))
		{
			__result = s_teamColors[team];
			return false;
		}
		__result = Color.magenta;
		return false;
	}

	private static bool TeamColorPaletteData_GetMaterial_Prefix(TeamColorPaletteData __instance, Team team, ref Material __result)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: 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_026e: Expected O, but got Unknown
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Expected O, but got Unknown
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: 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_015d: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_0650: Unknown result type (might be due to invalid IL or missing references)
		//IL_066c: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
		if ((int)team == 0 || (int)team == 1)
		{
			return true;
		}
		int paletteKey = GetPaletteKey(__instance);
		if (!s_paletteTeamMaterials.ContainsKey(paletteKey))
		{
			s_paletteTeamMaterials[paletteKey] = new Dictionary<Team, Material>();
		}
		Dictionary<Team, Material> dictionary = s_paletteTeamMaterials[paletteKey];
		if (dictionary.ContainsKey(team))
		{
			__result = dictionary[team];
			return false;
		}
		Material val = __instance.m_materialRed;
		if ((Object)(object)val == (Object)null)
		{
			val = __instance.m_materialBlue;
		}
		if ((Object)(object)val == (Object)null)
		{
			Debug.LogWarning((object)$"[MultiTeamPatches] TeamColorPaletteData没有Red或Blue材质,无法为队伍{team}创建材质");
			__result = null;
			return false;
		}
		Color val2 = (s_teamColors.ContainsKey(team) ? s_teamColors[team] : Color.white);
		float num = (s_teamAlphas.ContainsKey(team) ? s_teamAlphas[team] : 1f);
		float num2 = (s_teamEmissions.ContainsKey(team) ? s_teamEmissions[team] : 0f);
		bool num3 = num2 > 0f;
		bool flag = num < 1f;
		Material val3 = null;
		Shader val4 = null;
		if (num3 || flag)
		{
			Shader val5 = Shader.Find("Standard");
			if ((Object)(object)val5 != (Object)null)
			{
				val3 = new Material(val5);
				val4 = val5;
			}
			else
			{
				Shader val6 = Shader.Find("Unlit/Transparent");
				if ((Object)(object)val6 != (Object)null)
				{
					val3 = new Material(val6);
					val4 = val6;
				}
				else
				{
					val3 = new Material(val);
					val4 = val3.shader;
					Debug.LogWarning((object)"[MultiTeamPatches] TeamColorPaletteData无法找到支持发光/透明的shader,使用基础材质");
				}
			}
			if ((Object)(object)val3 != (Object)null && (Object)(object)val3.shader != (Object)(object)val.shader)
			{
				if (val.HasProperty("_MainTex") && val3.HasProperty("_MainTex"))
				{
					val3.SetTexture("_MainTex", val.GetTexture("_MainTex"));
				}
				if (val.HasProperty("_BumpMap") && val3.HasProperty("_BumpMap"))
				{
					val3.SetTexture("_BumpMap", val.GetTexture("_BumpMap"));
					if (val.HasProperty("_BumpScale") && val3.HasProperty("_BumpScale"))
					{
						val3.SetFloat("_BumpScale", val.GetFloat("_BumpScale"));
					}
				}
				if (val.HasProperty("_MetallicGlossMap") && val3.HasProperty("_MetallicGlossMap"))
				{
					val3.SetTexture("_MetallicGlossMap", val.GetTexture("_MetallicGlossMap"));
				}
			}
		}
		if ((Object)(object)val3 == (Object)null)
		{
			val3 = new Material(val);
			val4 = val3.shader;
		}
		((Object)val3).name = ((Object)val).name + "_" + ((object)(Team)(ref team)).ToString();
		Color val7 = default(Color);
		((Color)(ref val7))..ctor(val2.r, val2.g, val2.b, num);
		if (num2 > 0f)
		{
			((Color)(ref val7))..ctor(Mathf.Min(val2.r * (1f + num2), 1f), Mathf.Min(val2.g * (1f + num2), 1f), Mathf.Min(val2.b * (1f + num2), 1f), num);
		}
		if (val3.HasProperty("_Color"))
		{
			val3.SetColor("_Color", val7);
		}
		if (val3.HasProperty("_BaseColor"))
		{
			val3.SetColor("_BaseColor", val7);
		}
		if (val3.HasProperty("_MainColor"))
		{
			val3.SetColor("_MainColor", val7);
		}
		if (val3.HasProperty("_TintColor"))
		{
			val3.SetColor("_TintColor", val7);
		}
		if (num2 > 0f)
		{
			Color val8 = val2 * num2;
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", val8);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			else if (val3.HasProperty("_Emission"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_Emission", val8);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			if (val3.HasProperty("_EmissionIntensity"))
			{
				val3.SetFloat("_EmissionIntensity", num2);
			}
			if (!val3.HasProperty("_EmissionColor") && !val3.HasProperty("_Emission"))
			{
				Debug.LogWarning((object)("[MultiTeamPatches] TeamColorPaletteData材质 " + ((Object)val3).name + " 的Shader " + (((val4 != null) ? ((Object)val4).name : null) ?? "null") + " 不支持发光度属性,已通过增强颜色亮度模拟发光效果"));
			}
		}
		else if (val3.HasProperty("_EmissionColor") || val3.HasProperty("_Emission"))
		{
			val3.DisableKeyword("_EMISSION");
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.SetColor("_EmissionColor", Color.black);
			}
			if (val3.HasProperty("_Emission"))
			{
				val3.SetColor("_Emission", Color.black);
			}
			val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)4;
		}
		if (num < 1f)
		{
			if (val3.HasProperty("_SrcBlend") || val3.HasProperty("_Mode") || ((Object)(object)val4 != (Object)null && (((Object)val4).name.Contains("Transparent") || ((Object)val4).name.Contains("Alpha"))))
			{
				if (val3.HasProperty("_SrcBlend"))
				{
					val3.SetInt("_SrcBlend", 5);
				}
				if (val3.HasProperty("_DstBlend"))
				{
					val3.SetInt("_DstBlend", 10);
				}
				val3.renderQueue = 3000;
				val3.DisableKeyword("_ALPHATEST_ON");
				val3.EnableKeyword("_ALPHABLEND_ON");
				val3.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				if (val3.HasProperty("_Mode"))
				{
					val3.SetFloat("_Mode", 3f);
				}
				val3.SetOverrideTag("RenderType", "Transparent");
			}
			else
			{
				Color val9 = default(Color);
				((Color)(ref val9))..ctor(val7.r * num, val7.g * num, val7.b * num, 1f);
				if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", val9);
				}
				if (val3.HasProperty("_BaseColor"))
				{
					val3.SetColor("_BaseColor", val9);
				}
				if (val3.HasProperty("_MainColor"))
				{
					val3.SetColor("_MainColor", val9);
				}
				Debug.LogWarning((object)string.Format("[MultiTeamPatches] TeamColorPaletteData材质 {0} 的Shader {1} 不支持透明度,已通过降低颜色亮度模拟半透明效果: Alpha={2:F2}, 模拟颜色={3}", ((Object)val3).name, ((val4 != null) ? ((Object)val4).name : null) ?? "null", num, val9));
			}
		}
		else
		{
			if (val3.HasProperty("_Mode"))
			{
				val3.SetFloat("_Mode", 0f);
			}
			val3.DisableKeyword("_ALPHABLEND_ON");
			val3.SetOverrideTag("RenderType", "Opaque");
		}
		dictionary[team] = val3;
		__result = val3;
		return false;
	}

	private static void PatchTeamColor(Harmony harmony)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		MethodInfo method = typeof(TeamColor).GetMethod("GetTeamMaterial", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamColor_GetTeamMaterial_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method2 = typeof(TeamColor).GetMethod("UpdateTeamColors", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
		if (method2 != null)
		{
			harmony.Patch((MethodBase)method2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamColor_UpdateTeamColors_Transpiler", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool TeamColor_GetTeamMaterial_Prefix(TeamColor __instance, Team team, ref Material __result)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: 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_026e: Expected O, but got Unknown
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Expected O, but got Unknown
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: 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_015d: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_0397: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0601: Unknown result type (might be due to invalid IL or missing references)
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_0650: Unknown result type (might be due to invalid IL or missing references)
		//IL_066c: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
		if ((int)team == 0 || (int)team == 1)
		{
			return true;
		}
		int instanceID = ((Object)__instance).GetInstanceID();
		if (!s_teamColorMaterials.ContainsKey(instanceID))
		{
			s_teamColorMaterials[instanceID] = new Dictionary<Team, Material>();
		}
		Dictionary<Team, Material> dictionary = s_teamColorMaterials[instanceID];
		if (dictionary.ContainsKey(team))
		{
			__result = dictionary[team];
			return false;
		}
		Material val = __instance.redMaterial;
		if ((Object)(object)val == (Object)null)
		{
			val = __instance.blueMaterial;
		}
		if ((Object)(object)val == (Object)null)
		{
			Debug.LogWarning((object)$"[MultiTeamPatches] TeamColor没有Red或Blue材质,无法为队伍{team}创建材质");
			__result = null;
			return false;
		}
		Color val2 = (s_teamColors.ContainsKey(team) ? s_teamColors[team] : Color.white);
		float num = (s_teamAlphas.ContainsKey(team) ? s_teamAlphas[team] : 1f);
		float num2 = (s_teamEmissions.ContainsKey(team) ? s_teamEmissions[team] : 0f);
		bool num3 = num2 > 0f;
		bool flag = num < 1f;
		Material val3 = null;
		Shader val4 = null;
		if (num3 || flag)
		{
			Shader val5 = Shader.Find("Standard");
			if ((Object)(object)val5 != (Object)null)
			{
				val3 = new Material(val5);
				val4 = val5;
			}
			else
			{
				Shader val6 = Shader.Find("Unlit/Transparent");
				if ((Object)(object)val6 != (Object)null)
				{
					val3 = new Material(val6);
					val4 = val6;
				}
				else
				{
					val3 = new Material(val);
					val4 = val3.shader;
					Debug.LogWarning((object)"[MultiTeamPatches] TeamColor无法找到支持发光/透明的shader,使用基础材质");
				}
			}
			if ((Object)(object)val3 != (Object)null && (Object)(object)val3.shader != (Object)(object)val.shader)
			{
				if (val.HasProperty("_MainTex") && val3.HasProperty("_MainTex"))
				{
					val3.SetTexture("_MainTex", val.GetTexture("_MainTex"));
				}
				if (val.HasProperty("_BumpMap") && val3.HasProperty("_BumpMap"))
				{
					val3.SetTexture("_BumpMap", val.GetTexture("_BumpMap"));
					if (val.HasProperty("_BumpScale") && val3.HasProperty("_BumpScale"))
					{
						val3.SetFloat("_BumpScale", val.GetFloat("_BumpScale"));
					}
				}
				if (val.HasProperty("_MetallicGlossMap") && val3.HasProperty("_MetallicGlossMap"))
				{
					val3.SetTexture("_MetallicGlossMap", val.GetTexture("_MetallicGlossMap"));
				}
			}
		}
		if ((Object)(object)val3 == (Object)null)
		{
			val3 = new Material(val);
			val4 = val3.shader;
		}
		((Object)val3).name = ((Object)val).name + "_" + ((object)(Team)(ref team)).ToString();
		Color val7 = default(Color);
		((Color)(ref val7))..ctor(val2.r, val2.g, val2.b, num);
		if (num2 > 0f)
		{
			((Color)(ref val7))..ctor(Mathf.Min(val2.r * (1f + num2), 1f), Mathf.Min(val2.g * (1f + num2), 1f), Mathf.Min(val2.b * (1f + num2), 1f), num);
		}
		if (val3.HasProperty("_Color"))
		{
			val3.SetColor("_Color", val7);
		}
		if (val3.HasProperty("_BaseColor"))
		{
			val3.SetColor("_BaseColor", val7);
		}
		if (val3.HasProperty("_MainColor"))
		{
			val3.SetColor("_MainColor", val7);
		}
		if (val3.HasProperty("_TintColor"))
		{
			val3.SetColor("_TintColor", val7);
		}
		if (num2 > 0f)
		{
			Color val8 = val2 * num2;
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", val8);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			else if (val3.HasProperty("_Emission"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_Emission", val8);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			if (val3.HasProperty("_EmissionIntensity"))
			{
				val3.SetFloat("_EmissionIntensity", num2);
			}
			if (!val3.HasProperty("_EmissionColor") && !val3.HasProperty("_Emission"))
			{
				Debug.LogWarning((object)("[MultiTeamPatches] TeamColor材质 " + ((Object)val3).name + " 的Shader " + (((val4 != null) ? ((Object)val4).name : null) ?? "null") + " 不支持发光度属性,已通过增强颜色亮度模拟发光效果"));
			}
		}
		else if (val3.HasProperty("_EmissionColor") || val3.HasProperty("_Emission"))
		{
			val3.DisableKeyword("_EMISSION");
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.SetColor("_EmissionColor", Color.black);
			}
			if (val3.HasProperty("_Emission"))
			{
				val3.SetColor("_Emission", Color.black);
			}
			val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)4;
		}
		if (num < 1f)
		{
			if (val3.HasProperty("_SrcBlend") || val3.HasProperty("_Mode") || ((Object)(object)val4 != (Object)null && (((Object)val4).name.Contains("Transparent") || ((Object)val4).name.Contains("Alpha"))))
			{
				if (val3.HasProperty("_SrcBlend"))
				{
					val3.SetInt("_SrcBlend", 5);
				}
				if (val3.HasProperty("_DstBlend"))
				{
					val3.SetInt("_DstBlend", 10);
				}
				val3.renderQueue = 3000;
				val3.DisableKeyword("_ALPHATEST_ON");
				val3.EnableKeyword("_ALPHABLEND_ON");
				val3.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				if (val3.HasProperty("_Mode"))
				{
					val3.SetFloat("_Mode", 3f);
				}
				val3.SetOverrideTag("RenderType", "Transparent");
			}
			else
			{
				Color val9 = default(Color);
				((Color)(ref val9))..ctor(val7.r * num, val7.g * num, val7.b * num, 1f);
				if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", val9);
				}
				if (val3.HasProperty("_BaseColor"))
				{
					val3.SetColor("_BaseColor", val9);
				}
				if (val3.HasProperty("_MainColor"))
				{
					val3.SetColor("_MainColor", val9);
				}
				Debug.LogWarning((object)string.Format("[MultiTeamPatches] TeamColor材质 {0} 的Shader {1} 不支持透明度,已通过降低颜色亮度模拟半透明效果: Alpha={2:F2}, 模拟颜色={3}", ((Object)val3).name, ((val4 != null) ? ((Object)val4).name : null) ?? "null", num, val9));
			}
		}
		else
		{
			if (val3.HasProperty("_Mode"))
			{
				val3.SetFloat("_Mode", 0f);
			}
			val3.DisableKeyword("_ALPHABLEND_ON");
			val3.SetOverrideTag("RenderType", "Opaque");
		}
		dictionary[team] = val3;
		__result = val3;
		return false;
	}

	private static IEnumerable<CodeInstruction> TeamColor_UpdateTeamColors_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> codes = instructions.ToList();
		bool foundSwitch = false;
		for (int i = 0; i < codes.Count; i++)
		{
			if (!foundSwitch && codes[i].opcode == OpCodes.Switch)
			{
				foundSwitch = true;
				yield return codes[i];
			}
			else
			{
				yield return codes[i];
			}
		}
	}

	private static void PatchTeamSingletons(Harmony harmony)
	{
		Debug.Log((object)"[MultiTeamPatches] TeamSingletons补丁:需要在具体类型上动态应用");
	}

	public static void PatchConcreteTeamSingletons<T>(Harmony harmony) where T : MonoBehaviour
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		Type typeFromHandle = typeof(T);
		MethodInfo method = typeFromHandle.GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamSingletons_Awake_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo method2 = typeFromHandle.GetMethod("GetTeamInstance", BindingFlags.Static | BindingFlags.Public);
		if (method2 != null)
		{
			harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamSingletons_GetTeamInstance_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void TeamSingletons_Awake_Postfix(MonoBehaviour __instance)
	{
		//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_004f: 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_0054: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		Type type = ((object)__instance).GetType();
		FieldInfo fieldInfo = type.BaseType?.GetField("team", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		if (fieldInfo == null)
		{
			fieldInfo = type.GetField("team", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}
		if (fieldInfo == null)
		{
			return;
		}
		Team val = (Team)fieldInfo.GetValue(__instance);
		if ((int)val != 0 && (int)val != 1)
		{
			if (!s_teamInstances.ContainsKey(type))
			{
				s_teamInstances[type] = new Dictionary<Team, MonoBehaviour>();
			}
			s_teamInstances[type][val] = __instance;
			Debug.Log((object)$"[MultiTeamPatches] 新队伍实例已创建: {val} - {type.Name}");
		}
	}

	private static bool TeamSingletons_GetTeamInstance_Prefix(Team team, ref MonoBehaviour __result)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		if ((int)team == 0 || (int)team == 1)
		{
			return true;
		}
		__result = null;
		return false;
	}

	private static void PatchTeamHolder(Harmony harmony)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		MethodInfo method = typeof(TeamHolder).GetMethod("SwitchTeam");
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamHolder_SwitchTeam_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool TeamHolder_SwitchTeam_Prefix(TeamHolder __instance)
	{
		//IL_001c: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		Team[] array = Enum.GetValues(typeof(Team)).Cast<Team>().ToArray();
		int num = Array.IndexOf(array, __instance.team);
		if (num >= 0)
		{
			int num2 = (num + 1) % array.Length;
			__instance.team = array[num2];
		}
		else
		{
			__instance.team = (Team)0;
		}
		return false;
	}

	private static void PatchTeamUtlity(Harmony harmony)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		MethodInfo method = typeof(TeamUtlity).GetMethod("GetOtherTeam");
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TeamUtlity_GetOtherTeam_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool TeamUtlity_GetOtherTeam_Prefix(Team team, ref Team __result)
	{
		//IL_001b: 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_003d: Invalid comparison between Unknown and I4
		Team[] array = Enum.GetValues(typeof(Team)).Cast<Team>().ToArray();
		int num = Array.IndexOf(array, team);
		if (num >= 0 && array.Length > 1)
		{
			int num2 = (num + 1) % array.Length;
			__result = array[num2];
		}
		else if ((int)team == 1)
		{
			__result = (Team)0;
		}
		else
		{
			__result = (Team)1;
		}
		return false;
	}

	private static void PatchWinCondition(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(WinCondition).GetMethod("GetColoredText", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("WinCondition_GetColoredText_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool WinCondition_GetColoredText_Prefix(WinCondition __instance, Team team, ref string __result)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Invalid comparison between Unknown and I4
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if ((int)team == 0 || (int)team == 1)
		{
			return true;
		}
		Color white = Color.white;
		white = ((!s_teamColors.ContainsKey(team)) ? Color.white : s_teamColors[team]);
		__result = "<color=#" + ColorUtility.ToHtmlStringRGB(white) + ">";
		return false;
	}

	public static void RegisterTeamColor(Team team, Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		RegisterTeamColor(team, color, color.a, 0f);
	}

	public static Color GetTeamColor(Team team)
	{
		//IL_0005: 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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (s_teamColors.ContainsKey(team))
		{
			return s_teamColors[team];
		}
		return Color.white;
	}

	public static Team[] GetAllTeams()
	{
		return Enum.GetValues(typeof(Team)).Cast<Team>().ToArray();
	}

	public static bool IsValidTeam(Team team)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		return Enum.IsDefined(typeof(Team), team);
	}

	private static int GetPaletteKey(TeamColorPaletteData palette)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		int num = palette.ColorIndex;
		if ((Object)(object)palette.m_materialRed != (Object)null)
		{
			num = num * 31 + ((Object)palette.m_materialRed).GetInstanceID();
		}
		if ((Object)(object)palette.m_materialBlue != (Object)null)
		{
			num = num * 31 + ((Object)palette.m_materialBlue).GetInstanceID();
		}
		return num;
	}

	private static void PatchTABCUnitUI(Harmony harmony)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		MethodInfo method = typeof(TABCUnitUI).GetMethod("Init");
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamPatches).GetMethod("TABCUnitUI_Init_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void TABCUnitUI_Init_Postfix(TABCUnitUI __instance, Unit unit)
	{
		//IL_000a: 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_0018: Invalid comparison between Unknown and I4
		//IL_0035: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!((Object)(object)unit == (Object)null) && (int)unit.Team != 0 && (int)unit.Team != 1 && ServiceLocator.GetService<GlobalSettingsHandler>().GetSettingsInstance("GAMEPLAY_FLIP_COLORS") != null)
			{
				Color color = (s_teamColors.ContainsKey(unit.Team) ? s_teamColors[unit.Team] : Color.white);
				if ((Object)(object)__instance.m_HealthBar != (Object)null)
				{
					((Graphic)__instance.m_HealthBar).color = color;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamPatches] TABCUnitUI.Init补丁执行失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	public static void RegisterTeamColor(Team team, Color color, float alpha, float emission)
	{
		//IL_0002: 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)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		Color value = default(Color);
		((Color)(ref value))..ctor(color.r, color.g, color.b, 1f);
		s_teamColors[team] = value;
		s_teamAlphas[team] = Mathf.Clamp01(alpha);
		s_teamEmissions[team] = Mathf.Clamp(emission, 0f, 2f);
		ClearTeamMaterialCache(team);
	}

	private static void ClearTeamMaterialCache(Team team)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		new List<int>();
		foreach (KeyValuePair<int, Dictionary<Team, Material>> s_paletteTeamMaterial in s_paletteTeamMaterials)
		{
			if (s_paletteTeamMaterial.Value.ContainsKey(team))
			{
				s_paletteTeamMaterial.Value.Remove(team);
			}
		}
		foreach (KeyValuePair<int, Dictionary<Team, Material>> s_teamColorMaterial in s_teamColorMaterials)
		{
			if (s_teamColorMaterial.Value.ContainsKey(team))
			{
				s_teamColorMaterial.Value.Remove(team);
			}
		}
	}

	public static float GetTeamAlpha(Team team)
	{
		//IL_0005: 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)
		if (!s_teamAlphas.ContainsKey(team))
		{
			return 1f;
		}
		return s_teamAlphas[team];
	}

	public static float GetTeamEmission(Team team)
	{
		//IL_0005: 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)
		if (!s_teamEmissions.ContainsKey(team))
		{
			return 0f;
		}
		return s_teamEmissions[team];
	}
}
internal static class MultiTeamInputPatches
{
	private static TeamMenuUI s_teamMenu;

	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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		try
		{
			Debug.Log((object)"[MultiTeamInputPatches] 正在应用多队伍输入补丁...");
			Harmony val = new Harmony("Mod_Name.MultiTeamInput");
			MethodInfo method = typeof(UnitPlacementBrush).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public);
			if (method != null)
			{
				val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamInputPatches).GetMethod("UnitPlacementBrush_Update_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo method2 = typeof(UnitPlacementBrush).GetMethod("GetTeamAtCursorPosition", BindingFlags.Instance | BindingFlags.Public);
			if (method2 != null)
			{
				val.Patch((MethodBase)method2, new HarmonyMethod(typeof(MultiTeamInputPatches).GetMethod("UnitPlacementBrush_GetTeamAtCursorPosition_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo method3 = typeof(BrushBehaviourBase).GetMethod("GetTeamAreaAtPosition", BindingFlags.Instance | BindingFlags.Public);
			if (method3 != null)
			{
				val.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamInputPatches).GetMethod("BrushBehaviourBase_GetTeamAreaAtPosition_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo method4 = typeof(BrushBehaviourBase).GetMethod("HoveringStaticSceneObjects", BindingFlags.Instance | BindingFlags.Public);
			if (method4 != null)
			{
				val.Patch((MethodBase)method4, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamInputPatches).GetMethod("BrushBehaviourBase_HoveringStaticSceneObjects_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			InitializeTeamMenu();
			Debug.Log((object)"[MultiTeamInputPatches] 多队伍输入补丁应用完成!");
			Debug.Log((object)"[MultiTeamInputPatches] 快捷键说明:");
			Debug.Log((object)"[MultiTeamInputPatches]   - T键: 打开/关闭队伍菜单(仅在放置阶段可用)");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamInputPatches] 应用补丁时发生错误: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void UnitPlacementBrush_Update_Postfix(UnitPlacementBrush __instance)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameModeService gameModeService = __instance.GameModeService;
		if (((gameModeService != null) ? gameModeService.CurrentGameMode : null) != null)
		{
			GameStateManager service = ServiceLocator.GetService<GameStateManager>();
			if (service != null && (int)service.GameState == 0 && Input.GetKeyDown((KeyCode)116))
			{
				ToggleTeamMenu();
			}
		}
	}

	private static bool UnitPlacementBrush_GetTeamAtCursorPosition_Prefix(UnitPlacementBrush __instance, ref Team __result)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected I4, but got Unknown
		if ((Object)(object)s_teamMenu != (Object)null && s_teamMenu.HasSelectedTeam())
		{
			Team? selectedTeamForPlacement = s_teamMenu.GetSelectedTeamForPlacement();
			if (selectedTeamForPlacement.HasValue)
			{
				__result = (Team)(int)selectedTeamForPlacement.Value;
				return false;
			}
		}
		return true;
	}

	private static void BrushBehaviourBase_GetTeamAreaAtPosition_Postfix(ref Team __result)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected I4, but got Unknown
		if ((Object)(object)s_teamMenu != (Object)null && s_teamMenu.HasSelectedTeam())
		{
			Team? selectedTeamForPlacement = s_teamMenu.GetSelectedTeamForPlacement();
			if (selectedTeamForPlacement.HasValue)
			{
				__result = (Team)(int)selectedTeamForPlacement.Value;
			}
		}
	}

	private static void BrushBehaviourBase_HoveringStaticSceneObjects_Postfix(BrushBehaviourBase __instance, GameObject go, Vector3 worldPosition, Vector3 surfaceNormal)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)s_teamMenu != (Object)null) || !s_teamMenu.HasSelectedTeam())
		{
			return;
		}
		Team? selectedTeamForPlacement = s_teamMenu.GetSelectedTeamForPlacement();
		if (selectedTeamForPlacement.HasValue)
		{
			Team value = selectedTeamForPlacement.Value;
			Quaternion val = default(Quaternion);
			if (TeamEnumExtension.IsExtendedTeam(value) && __instance.GetTeamAreaAtPosition(worldPosition, ref val) == value)
			{
				__instance.UnitPlacementBrush.Cursor.SetCursorState((PlacementCursorState)1);
			}
		}
	}

	private static void InitializeTeamMenu()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		try
		{
			GameObject val = new GameObject("TeamMenuInitializer");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<TeamMenuInitializer>();
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamInputPatches] 初始化队伍菜单失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void ToggleTeamMenu()
	{
		if ((Object)(object)s_teamMenu == (Object)null)
		{
			s_teamMenu = TeamMenuUI.Create();
		}
		if ((Object)(object)s_teamMenu != (Object)null)
		{
			if (s_teamMenu.IsOpen())
			{
				s_teamMenu.Close();
			}
			else
			{
				s_teamMenu.Show();
			}
		}
	}
}
[BepInPlugin("Mod_Name.MultiTeam", "多队伍系统", "1.0.0")]
internal class MultiTeamInitializer : BaseUnityPlugin
{
	private void Awake()
	{
		((MonoBehaviour)this).StartCoroutine(InitializeMultiTeamSystem());
	}

	private IEnumerator InitializeMultiTeamSystem()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
		yield return (object)new WaitForSecondsRealtime(0.5f);
		try
		{
			Debug.Log((object)"[MultiTeamInitializer] 开始初始化多队伍系统...");
			TeamEnumExtension.Initialize();
			MultiTeamPatches.ApplyPatches();
			MultiTeamAIPatches.ApplyPatches();
			BattleBudgetPatches.ApplyPatches();
			MultiTeamBattlePatches.ApplyPatches();
			MultiTeamCampaignSerialization.ApplyPatches();
			Debug.Log((object)"[MultiTeamInitializer] 多队伍系统初始化完成!");
			Debug.Log((object)"[MultiTeamInitializer] 支持队伍: Red, Blue, Green, Yellow, Purple, Orange");
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamInitializer] 初始化失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}
}
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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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)
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		foreach (Team val in allTeamsIncludingExtended)
		{
			if (TeamEnumExtension.IsExtendedTeam(val))
			{
				EnsureTeamExists(__instance, val);
				MethodInfo method = typeof(BattleBudget).GetMethod("SetBudget", new Type[2]
				{
					typeof(Team),
					typeof(int)
				});
				if (method != null)
				{
					method.Invoke(__instance, new object[2] { val, budget });
				}
			}
		}
	}

	private static void EnsureTeamExists(BattleBudget instance, Team team)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Expected O, but got Unknown
		//IL_00ce: 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)
		FieldInfo field = typeof(BattleBudget).GetField("m_teamBudgets", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null || !(field.GetValue(instance) is Dictionary<Team, BaseWallet> dictionary) || dictionary.ContainsKey(team) || dictionary.Count == 0)
		{
			return;
		}
		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)
		{
			return;
		}
		Type type = s_lastWalletType ?? ((object)val).GetType();
		if (type == null)
		{
			type = ((object)val).GetType();
		}
		try
		{
			BaseWallet val2 = (BaseWallet)Activator.CreateInstance(type);
			val2.SetTeamOwner(team);
			FieldInfo field2 = typeof(BattleBudget).GetField("m_originalBudget", BindingFlags.Instance | BindingFlags.NonPublic);
			int num = 0;
			if (field2 != null)
			{
				num = (int)field2.GetValue(instance);
			}
			if (num == 0 && dictionary.ContainsKey((Team)0))
			{
				num = dictionary[(Team)0].GetBudget();
			}
			if (num == 0 && dictionary.ContainsKey((Team)1))
			{
				num = dictionary[(Team)1].GetBudget();
			}
			val2.SetBudget(num);
			dictionary[team] = val2;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[BattleBudgetPatches] 创建钱包失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	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_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 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_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;
	}
}
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 bool s_reflectionCacheInitialized = false;

	private static int s_lastBattleTeamCount = 0;

	private static PropertyInfo s_entityManagerProperty;

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

	private static GameStateManager s_gameStateManager = null;

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

	private static Team[] s_cachedAllTeams = null;

	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 PatchCheckClosestUnitTargets(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(CheckClosestUnitTargets).GetMethod("GetUnitsAndSort", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(MultiTeamAIPatches).GetMethod("CheckClosestUnitTargets_GetUnitsAndSort_Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static bool CheckClosestUnitTargets_GetUnitsAndSort_Prefix(CheckClosestUnitTargets __instance, ref List<Unit> __result)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			FieldInfo field = typeof(CheckClosestUnitTargets).GetField("m_teamSystem", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return true;
			}
			TeamSystem val = (TeamSystem)field.GetValue(__instance);
			if (val == null)
			{
				return true;
			}
			MethodInfo method = typeof(CheckClosestUnitTargets).GetMethod("GetTeam", BindingFlags.Instance | BindingFlags.NonPublic);
			if (method == null)
			{
				return true;
			}
			Team val2 = (Team)method.Invoke(__instance, null);
			List<Unit> list = new List<Unit>();
			Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
			foreach (Team val3 in allTeamsIncludingExtended)
			{
				if (val3 != val2)
				{
					List<Unit> teamUnits = val.GetTeamUnits(val3);
					list.AddRange(teamUnits);
				}
			}
			Transform transform = ((Component)__instance).transform;
			list.Sort((Unit x, Unit y) => Vector3.Distance(transform.position, x.data.mainRig.position).CompareTo(Vector3.Distance(transform.position, y.data.mainRig.position)));
			__result = list;
			return false;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] CheckClosestUnitTargets补丁执行失败: " + ex.Message + "\n" + ex.StackTrace));
			return true;
		}
	}

	private static void PatchTeamSystemTriggerUnitDeathAction(Harmony harmony)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		MethodInfo method = typeof(TeamSystem).GetMethod("TriggerUnitDeathAction");
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamAIPatches).GetMethod("TeamSystem_TriggerUnitDeathAction_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}

	private static void TeamSystem_TriggerUnitDeathAction_Postfix(TeamSystem __instance)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(TeamSystem).GetField("m_winConditionUnits", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null || !(field.GetValue(__instance) is Dictionary<Team, List<Unit>> dictionary))
		{
			return;
		}
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		int num = 0;
		Team[] array = allTeamsIncludingExtended;
		foreach (Team key in array)
		{
			if (dictionary.ContainsKey(key) && dictionary[key].Count > 0)
			{
				num++;
			}
		}
		PropertyInfo property = typeof(TeamSystem).GetProperty("OnlyOneTeamAlive");
		if (property != null)
		{
			property.SetValue(__instance, num == 1, null);
		}
	}

	private static void SetFieldValue(object obj, string fieldName, object value)
	{
		FieldInfo field = obj.GetType().GetField(fieldName);
		if (field != null)
		{
			field.SetValue(obj, value);
		}
	}

	private static void FindEnemyTargetSystem_OnUpdate_Postfix(FindEnemyTargetSystem __instance, ref JobHandle __result, JobHandle inputDeps)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: 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_0249: 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_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: 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_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: 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_0206: Expected I4, but got Unknown
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: 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_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_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: 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_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: 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_02a0: 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_02ad: 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_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0339: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0348: Expected I4, but got Unknown
		//IL_0348: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0383: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0467: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Unknown result type (might be due to invalid IL or missing references)
		//IL_048d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: 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_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			((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>();
			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))
						{
							continue;
						}
						if (m < componentDataArray.Length)
						{
							dictionary3[key] = componentDataArray[m];
							continue;
						}
						BeingTargetedBy val10;
						if (!dictionary.ContainsKey(key))
						{
							BeingTargetedBy val9 = default(BeingTargetedBy);
							val9.Value = 0f;
							val10 = val9;
						}
						else
						{
							val10 = dictionary[key];
						}
						BeingTargetedBy val11 = val10;
						float num3 = (dictionary2.ContainsKey(key) ? dictionary2[key] : 0f);
						dictionary3[key] = new BeingTargetedBy
						{
							Value = val11.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 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 PatchFindFriendlyHighestPriceTargetSystem(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(FindFriendlyHighestPriceTargetSystem).GetMethod("OnUpdate", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method != null)
		{
			harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(typeof(MultiTeamAIPatches).GetMethod("FindFriendlyHighestPriceTargetSystem_OnUpdate_Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Debug.Log((object)"[MultiTeamAIPatches] FindFriendlyHighestPriceTargetSystem补丁已应用");
		}
	}

	private static void FindFriendlyHighestPriceTargetSystem_OnUpdate_Postfix(FindFriendlyHighestPriceTargetSystem __instance, ref JobHandle __result, JobHandle inputDeps)
	{
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			((JobHandle)(ref __result)).Complete();
			Team[] allTeamsCached = GetAllTeamsCached();
			if (allTeamsCached == null || allTeamsCached.Length <= 2)
			{
				return;
			}
			FieldInfo field = typeof(FindFriendlyHighestPriceTargetSystem).GetField("m_filter", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(FindFriendlyHighestPriceTargetSystem).GetField("m_targetFilter", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeof(FindFriendlyHighestPriceTargetSystem).GetField("m_barrier", BindingFlags.Instance | BindingFlags.NonPublic);
			PropertyInfo property = typeof(FindFriendlyHighestPriceTargetSystem).GetProperty("ComponentGroups", BindingFlags.Instance | BindingFlags.Public);
			if (field == null || field2 == null || field3 == null || property == null)
			{
				return;
			}
			object value = field.GetValue(__instance);
			object value2 = field2.GetValue(__instance);
			object value3 = field3.GetValue(__instance);
			ComponentGroup[] array = (ComponentGroup[])property.GetValue(__instance);
			if (value == null || value2 == null || value3 == null || array == null)
			{
				return;
			}
			FieldInfo field4 = value.GetType().GetField("GroupIndex", BindingFlags.Instance | BindingFlags.Public);
			FieldInfo field5 = value2.GetType().GetField("GroupIndex", BindingFlags.Instance | BindingFlags.Public);
			if (field4 == null || field5 == null)
			{
				return;
			}
			int num = (int)field4.GetValue(value);
			int num2 = (int)field5.GetValue(value2);
			if (num < 0 || num >= array.Length || num2 < 0 || num2 >= array.Length)
			{
				return;
			}
			ComponentGroup val = array[num];
			ComponentGroup val2 = array[num2];
			if (val == null || val2 == null)
			{
				return;
			}
			MethodInfo method = value3.GetType().GetMethod("CreateCommandBuffer");
			if (!(method == null))
			{
				EntityCommandBuffer commandBuffer = (EntityCommandBuffer)method.Invoke(value3, null);
				ComponentDataFromEntity<HasTargetTag> componentDataFromEntity = ((ComponentSystemBase)__instance).GetComponentDataFromEntity<HasTargetTag>(true);
				for (int i = 2; i < allTeamsCached.Length; i++)
				{
					Team team = allTeamsCached[i];
					ProcessFriendlyHighestPriceTeamPair(__instance, val, val2, team, componentDataFromEntity, commandBuffer);
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[MultiTeamAIPatches] FindFriendlyHighestPriceTargetSystem补丁执行失败: " + ex.Message + "\n" + ex.StackTrace));
		}
	}

	private static void ProcessFriendlyHighestPriceTeamPair(FindFriendlyHighestPriceTargetSystem instance, ComponentGroup unitGroup, ComponentGroup targetGroup, Team team, ComponentDataFromEntity<HasTargetTag> hasTargetTag, EntityCommandBuffer commandBuffer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected I4, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected I4, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_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_0069: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: 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_00da: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: 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_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unk