Decompiled source of Foreign forces v1.0.8

Foreign_forces.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.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();
			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_029b: 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_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_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: 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_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0414: Unknown result type (might be due to invalid IL or missing references)
		//IL_0419: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0475: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0461: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_06da: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0717: Unknown result type (might be due to invalid IL or missing references)
		//IL_0733: Unknown result type (might be due to invalid IL or missing references)
		//IL_074f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0791: 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 color = Color.white;
		if (val.HasProperty("_Color"))
		{
			color = val.GetColor("_Color");
		}
		else if (val.HasProperty("_BaseColor"))
		{
			color = val.GetColor("_BaseColor");
		}
		else if (val.HasProperty("_MainColor"))
		{
			color = val.GetColor("_MainColor");
		}
		else if (val.HasProperty("_TintColor"))
		{
			color = val.GetColor("_TintColor");
		}
		Color val7 = ChangeHue(color, val2);
		Color val8 = default(Color);
		((Color)(ref val8))..ctor(val7.r, val7.g, val7.b, num);
		if (num2 > 0f)
		{
			((Color)(ref val8))..ctor(Mathf.Min(val7.r * (1f + num2), 1f), Mathf.Min(val7.g * (1f + num2), 1f), Mathf.Min(val7.b * (1f + num2), 1f), num);
		}
		if (val3.HasProperty("_Color"))
		{
			val3.SetColor("_Color", val8);
		}
		if (val3.HasProperty("_BaseColor"))
		{
			val3.SetColor("_BaseColor", val8);
		}
		if (val3.HasProperty("_MainColor"))
		{
			val3.SetColor("_MainColor", val8);
		}
		if (val3.HasProperty("_TintColor"))
		{
			val3.SetColor("_TintColor", val8);
		}
		if (num2 > 0f)
		{
			Color val9 = Color.black;
			if (val.HasProperty("_EmissionColor"))
			{
				val9 = val.GetColor("_EmissionColor");
			}
			else if (val.HasProperty("_Emission"))
			{
				val9 = val.GetColor("_Emission");
			}
			Color val10 = ((!(val9 != Color.black)) ? (val2 * num2) : (ChangeHue(val9, val2) * num2));
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", val10);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			else if (val3.HasProperty("_Emission"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_Emission", val10);
				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 val11 = default(Color);
				((Color)(ref val11))..ctor(val8.r * num, val8.g * num, val8.b * num, 1f);
				if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", val11);
				}
				if (val3.HasProperty("_BaseColor"))
				{
					val3.SetColor("_BaseColor", val11);
				}
				if (val3.HasProperty("_MainColor"))
				{
					val3.SetColor("_MainColor", val11);
				}
				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, val11));
			}
		}
		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_029b: 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_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_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: 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_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_0414: Unknown result type (might be due to invalid IL or missing references)
		//IL_0419: Unknown result type (might be due to invalid IL or missing references)
		//IL_042e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0433: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_044f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0475: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0461: Unknown result type (might be due to invalid IL or missing references)
		//IL_0462: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Unknown result type (might be due to invalid IL or missing references)
		//IL_06da: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0717: Unknown result type (might be due to invalid IL or missing references)
		//IL_0733: Unknown result type (might be due to invalid IL or missing references)
		//IL_074f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0791: 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 color = Color.white;
		if (val.HasProperty("_Color"))
		{
			color = val.GetColor("_Color");
		}
		else if (val.HasProperty("_BaseColor"))
		{
			color = val.GetColor("_BaseColor");
		}
		else if (val.HasProperty("_MainColor"))
		{
			color = val.GetColor("_MainColor");
		}
		else if (val.HasProperty("_TintColor"))
		{
			color = val.GetColor("_TintColor");
		}
		Color val7 = ChangeHue(color, val2);
		Color val8 = default(Color);
		((Color)(ref val8))..ctor(val7.r, val7.g, val7.b, num);
		if (num2 > 0f)
		{
			((Color)(ref val8))..ctor(Mathf.Min(val7.r * (1f + num2), 1f), Mathf.Min(val7.g * (1f + num2), 1f), Mathf.Min(val7.b * (1f + num2), 1f), num);
		}
		if (val3.HasProperty("_Color"))
		{
			val3.SetColor("_Color", val8);
		}
		if (val3.HasProperty("_BaseColor"))
		{
			val3.SetColor("_BaseColor", val8);
		}
		if (val3.HasProperty("_MainColor"))
		{
			val3.SetColor("_MainColor", val8);
		}
		if (val3.HasProperty("_TintColor"))
		{
			val3.SetColor("_TintColor", val8);
		}
		if (num2 > 0f)
		{
			Color val9 = Color.black;
			if (val.HasProperty("_EmissionColor"))
			{
				val9 = val.GetColor("_EmissionColor");
			}
			else if (val.HasProperty("_Emission"))
			{
				val9 = val.GetColor("_Emission");
			}
			Color val10 = ((!(val9 != Color.black)) ? (val2 * num2) : (ChangeHue(val9, val2) * num2));
			if (val3.HasProperty("_EmissionColor"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_EmissionColor", val10);
				val3.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			else if (val3.HasProperty("_Emission"))
			{
				val3.EnableKeyword("_EMISSION");
				val3.SetColor("_Emission", val10);
				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 val11 = default(Color);
				((Color)(ref val11))..ctor(val8.r * num, val8.g * num, val8.b * num, 1f);
				if (val3.HasProperty("_Color"))
				{
					val3.SetColor("_Color", val11);
				}
				if (val3.HasProperty("_BaseColor"))
				{
					val3.SetColor("_BaseColor", val11);
				}
				if (val3.HasProperty("_MainColor"))
				{
					val3.SetColor("_MainColor", val11);
				}
				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, val11));
			}
		}
		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];
	}

	private static Color ChangeHue(Color color, Color hue)
	{
		//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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: 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)
		float a = color.a;
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(color, ref num, ref num2, ref num3);
		float num4 = default(float);
		float num5 = default(float);
		float num6 = default(float);
		Color.RGBToHSV(hue, ref num4, ref num5, ref num6);
		float num7 = ((num5 > 0.07f) ? num2 : num5);
		float num8 = ((num6 < 0.3f) ? (num6 * 0.7f + num3 * 0.3f) : ((!(num6 > 0.7f)) ? (num6 * 0.5f + num3 * 0.5f) : (num6 * 0.3f + num3 * 0.7f)));
		Color val = Color.HSVToRGB(num4, num7, num8);
		return new Color(val.r, val.g, val.b, a);
	}
}
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]   - Shift+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.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) && 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();
			AssassinPoofEffectTeamFix.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_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		bool flag2 = false;
		try
		{
			GameModeService service = ServiceLocator.GetService<GameModeService>();
			if ((Object)(object)service != (Object)null && service.CurrentGameMode != null)
			{
				flag2 = ((object)service.CurrentGameMode).GetType().Name == "SandboxGameMode";
			}
			FieldInfo field = typeof(BattleBudget).GetField("m_teamBudgets", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null && field.GetValue(__instance) is Dictionary<Team, BaseWallet> dictionary && dictionary.Count > 0)
			{
				foreach (BaseWallet value in dictionary.Values)
				{
					if (value != null && (((object)value).GetType().Name == "CampaignWallet" || flag2))
					{
						flag = true;
						break;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[BattleBudgetPatches] 检查钱包类型时出错: " + ex.Message));
		}
		Team[] allTeamsIncludingExtended = TeamEnumExtension.GetAllTeamsIncludingExtended();
		foreach (Team val in allTeamsIncludingExtended)
		{
			if (!TeamEnumExtension.IsExtendedTeam(val))
			{
				continue;
			}
			EnsureTeamExists(__instance, val);
			int num = ((!flag) ? budget : 0);
			MethodInfo method = typeof(BattleBudget).GetMethod("SetBudget", new Type[2]
			{
				typeof(Team),
				typeof(int)
			});
			if (method != null)
			{
				method.Invoke(__instance, new object[2] { val, num });
				if (flag)
				{
					string text = (flag2 ? "Sandbox模式" : "使用CampaignWallet");
					Debug.Log((object)("[BattleBudgetPatches] " + text + ":为扩展队伍 " + TeamEnumExtension.GetTeamName(val) + " 设置无限预算(0)"));
				}
			}
		}
	}

	private static void EnsureTeamExists(BattleBudget instance, Team team)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(BattleBudget).GetField("m_teamBudgets", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field == null)
		{
			Debug.LogWarning((object)"[BattleBudgetPatches] 无法找到 m_teamBudgets 字段");
		}
		else if (!(field.GetValue(instance) is Dictionary<Team, BaseWallet> dictionary))
		{
			Debug.LogWarning((object)"[BattleBudgetPatches] teamBudgets 字典为 null");
		}
		else
		{
			if (dictionary.ContainsKey(team))
			{
				return;
			}
			if (dictionary.Count != 0)
			{
				Type type = null;
				try
				{
					GameModeService service = ServiceLocator.GetService<GameModeService>();
					if ((Object)(object)service != (Object)null && service.CurrentGameMode != null)
					{
						Type type2 = ((object)service.CurrentGameMode).GetType();
						if (type2.Name == "CampaignGameMode")
						{
							type = typeof(CampaignWallet);
						}
						else if (type2.Name == "SandboxGameMode")
						{
							type = typeof(SandboxWallet);
						}
						else if (type2.Name == "LocalMultiplayerGameMode" || type2.Name == "OnlineMultiplayerGameMode")
						{
							type = typeof(LocalMultiplayerWallet);
						}
					}
				}
				catch (Exception ex)
				{
					Debug.LogWarning((object)("[BattleBudgetPatches] EnsureTeamExists: 检查游戏模式时出错: " + ex.Message));
				}
				if (type == null)
				{
					BaseWallet val = null;
					foreach (BaseWallet value in dictionary.Values)
					{
						if (value != null)
						{
							val = value;
							if (s_lastWalletType == null)
							{
								s_lastWalletType = ((object)value).GetType();
							}
							break;
						}
					}
					if (val == null)
					{
						Debug.LogWarning((object)("[BattleBudgetPatches] 无法为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 创建钱包:找不到模板钱包"));
						return;
					}
					type = s_lastWalletType ?? ((object)val).GetType();
					if (type == null)
					{
						type = ((object)val).GetType();
					}
				}
				try
				{
					BaseWallet val2 = (BaseWallet)Activator.CreateInstance(type);
					val2.SetTeamOwner(team);
					bool num = type.Name == "CampaignWallet";
					FieldInfo field2 = typeof(BattleBudget).GetField("m_originalBudget", BindingFlags.Instance | BindingFlags.NonPublic);
					int num2 = 0;
					if (field2 != null)
					{
						num2 = (int)field2.GetValue(instance);
					}
					if (num2 == 0 && dictionary.ContainsKey((Team)0))
					{
						num2 = dictionary[(Team)0].GetBudget();
					}
					if (num2 == 0 && dictionary.ContainsKey((Team)1))
					{
						num2 = dictionary[(Team)1].GetBudget();
					}
					if (num)
					{
						num2 = 0;
						Debug.Log((object)("[BattleBudgetPatches] EnsureTeamExists: 使用CampaignWallet:为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 设置无限预算(0)"));
					}
					val2.SetBudget(num2);
					dictionary[team] = val2;
					Debug.Log((object)$"[BattleBudgetPatches] 自动为扩展队伍 {TeamEnumExtension.GetTeamName(team)} 创建了钱包,类型: {type.Name}, 预算: {num2}");
					return;
				}
				catch (Exception ex2)
				{
					Debug.LogError((object)("[BattleBudgetPatches] 创建钱包失败: " + ex2.Message + "\n" + ex2.StackTrace));
					return;
				}
			}
			Debug.LogWarning((object)("[BattleBudgetPatches] 无法为扩展队伍 " + TeamEnumExtension.GetTeamName(team) + " 创建钱包:字典为空,可能尚未初始化"));
		}
	}

	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);