using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: IgnoresAccessChecksTo("SharedAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Team_Mode")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("Team_Mode")]
[assembly: AssemblyTitle("Team_Mode")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace Microsoft.CodeAnalysis
{
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace Team_Mode
{
[BepInPlugin("Team_Mode", "Team_Mode", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public static bool Enabled = false;
public static bool FriendlyFireEnabled = false;
public static int TeamCount = 2;
public static Dictionary<ulong, int> PlayerTeams = new Dictionary<ulong, int>();
public static readonly Color[] TeamColors = (Color[])(object)new Color[4]
{
new Color(0.9f, 0.2f, 0.2f),
new Color(0.2f, 0.4f, 0.9f),
new Color(0.2f, 0.8f, 0.2f),
new Color(0.9f, 0.8f, 0.1f)
};
public const string Id = "Team_Mode";
internal static ManualLogSource Log { get; private set; } = null;
public static string[] TeamNames => new string[4]
{
Lang.Get("Rouge", "Red"),
Lang.Get("Bleu", "Blue"),
Lang.Get("Vert", "Green"),
Lang.Get("Jaune", "Yellow")
};
public static string Name => "Team_Mode";
public static string Version => "0.1.0";
public static int GetTeam(ulong guid)
{
if (!PlayerTeams.TryGetValue(guid, out var value))
{
return 0;
}
return value;
}
public static bool SameTeam(ulong a, ulong b)
{
if (Enabled && TeamCount > 1)
{
return GetTeam(a) == GetTeam(b);
}
return false;
}
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("Team_Mode").PatchAll();
Log.LogInfo((object)("Plugin " + Name + " loaded!"));
}
}
[HarmonyPatch]
public class HittableHitWithItemPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("Hittable"), "HitWithItem", (Type[])null, (Type[])null);
}
[HarmonyPrefix]
private static bool Prefix(object __instance, object itemUser)
{
if (!Plugin.Enabled)
{
return true;
}
try
{
object obj = __instance.GetType().GetProperty("AsEntity", BindingFlags.Instance | BindingFlags.Public)?.GetValue(__instance);
if (obj == null)
{
return true;
}
if (!(bool)(obj.GetType().GetProperty("IsPlayer", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj) ?? ((object)false)))
{
return true;
}
object obj2 = obj.GetType().GetProperty("PlayerInfo", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj);
if (obj2 == null)
{
return true;
}
ulong guid = GetGuid(obj2);
if (itemUser == null)
{
return true;
}
object obj3 = itemUser.GetType().GetProperty("PlayerInfo", BindingFlags.Instance | BindingFlags.Public)?.GetValue(itemUser);
if (obj3 == null)
{
return true;
}
ulong guid2 = GetGuid(obj3);
if (!Plugin.FriendlyFireEnabled && Plugin.SameTeam(guid2, guid))
{
Plugin.Log.LogInfo((object)"\ud83d\udee1\ufe0f Friendly fire bloqué (même équipe)");
return false;
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("HitWithItemPatch: " + ex.Message));
}
return true;
}
private static ulong GetGuid(object playerInfo)
{
object obj = playerInfo.GetType().GetProperty("PlayerId", BindingFlags.Instance | BindingFlags.Public)?.GetValue(playerInfo);
if (obj == null)
{
return 0uL;
}
return (ulong)(obj.GetType().GetProperty("Guid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj) ?? ((object)0uL));
}
}
[HarmonyPatch]
public class TeamScorePatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("CourseManager"), "InformPlayerScoredInternal", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object playerAsGolfer)
{
if (!Plugin.Enabled || Plugin.TeamCount <= 1)
{
return;
}
try
{
if (!(bool)(AccessTools.TypeByName("NetworkServer")?.GetProperty("active", BindingFlags.Static | BindingFlags.Public)?.GetValue(null) ?? ((object)false)))
{
return;
}
Type type = AccessTools.TypeByName("CourseManager");
object obj = (type.BaseType?.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy))?.GetValue(null);
if (obj == null)
{
return;
}
object obj2 = obj.GetType().GetField("playerStates", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj);
if (obj2 == null)
{
return;
}
MethodInfo method = obj2.GetType().GetMethod("get_Item");
int num = (int)(obj2.GetType().GetProperty("Count")?.GetValue(obj2) ?? ((object)0));
object obj3 = playerAsGolfer.GetType().GetProperty("connectionToClient", BindingFlags.Instance | BindingFlags.Public)?.GetValue(playerAsGolfer);
if (obj3 == null)
{
return;
}
MethodInfo method2 = obj.GetType().GetMethod("TryGetPlayerStateIndex", BindingFlags.Instance | BindingFlags.NonPublic);
object[] array = new object[2] { obj3, 0 };
if (method2 == null || !(bool)method2.Invoke(obj, array))
{
return;
}
int num2 = (int)array[1];
object obj4 = method?.Invoke(obj2, new object[1] { num2 });
if (obj4 == null)
{
return;
}
FieldInfo field = obj4.GetType().GetField("playerGuid", BindingFlags.Instance | BindingFlags.Public);
ulong num3 = (ulong)(field?.GetValue(obj4) ?? ((object)0uL));
int team = Plugin.GetTeam(num3);
FieldInfo field2 = obj4.GetType().GetField("courseScore", BindingFlags.Instance | BindingFlags.Public);
FieldInfo field3 = obj4.GetType().GetField("matchScore", BindingFlags.Instance | BindingFlags.Public);
int num4 = (int)(field2?.GetValue(obj4) ?? ((object)0));
int num5 = (int)(field3?.GetValue(obj4) ?? ((object)0));
if (num5 > 0)
{
ScoreboardTeamData.LastMatchScores.TryGetValue(num3, out var value);
if (value == 0)
{
ScoreboardTeamData.TotalMatchScores.TryGetValue(num3, out var value2);
ScoreboardTeamData.TotalMatchScores[num3] = value2 + num5;
}
else if (num5 > value)
{
int num6 = num5 - value;
ScoreboardTeamData.TotalMatchScores.TryGetValue(num3, out var value3);
ScoreboardTeamData.TotalMatchScores[num3] = value3 + num6;
}
ScoreboardTeamData.LastMatchScores[num3] = num5;
Plugin.Log.LogInfo((object)$"\ud83d\udcbe guid={num3} last={value} match={num5} → total={ScoreboardTeamData.TotalMatchScores[num3]}");
}
MethodInfo method3 = obj2.GetType().GetMethod("set_Item");
for (int i = 0; i < num; i++)
{
if (i == num2)
{
continue;
}
object obj5 = method?.Invoke(obj2, new object[1] { i });
if (obj5 == null)
{
continue;
}
ulong num7 = (ulong)(field?.GetValue(obj5) ?? ((object)0uL));
if (Plugin.SameTeam(num3, num7))
{
if (field2 != null)
{
field2.SetValue(obj5, num4);
}
if (field3 != null)
{
field3.SetValue(obj5, num5);
}
method3?.Invoke(obj2, new object[2] { i, obj5 });
if (num5 > 0 && ScoreboardTeamData.TotalMatchScores.TryGetValue(num3, out var value4))
{
ScoreboardTeamData.TotalMatchScores[num7] = value4;
}
Plugin.Log.LogInfo((object)("\ud83e\udd1d Score partagé avec coéquipier (équipe " + Plugin.TeamNames[team] + ")"));
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("TeamScorePatch: " + ex.Message));
}
}
}
[HarmonyPatch]
public class NameTagColorPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("NameTagUi"), "LateUpdate", (Type[])null, (Type[])null) ?? AccessTools.Method(AccessTools.TypeByName("NameTagUi"), "Update", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object __instance)
{
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Enabled)
{
return;
}
try
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
object obj = __instance.GetType().GetField("playerInfo", bindingAttr)?.GetValue(__instance);
if (obj == null)
{
return;
}
object obj2 = obj.GetType().GetProperty("PlayerId", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj);
if (obj2 != null)
{
ulong guid = (ulong)(obj2.GetType().GetProperty("Guid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2) ?? ((object)0uL));
object? obj3 = __instance.GetType().GetField("tag", bindingAttr)?.GetValue(__instance);
TMP_Text val = (TMP_Text)((obj3 is TMP_Text) ? obj3 : null);
if ((Object)(object)val != (Object)null)
{
((Graphic)val).color = Plugin.TeamColors[Plugin.GetTeam(guid)];
}
}
}
catch
{
}
}
}
[HarmonyPatch]
public class PlayerSkinColorPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("PlayerCosmeticsSwitcher"), "SetSkinColor", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object __instance)
{
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Enabled)
{
return;
}
try
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
object obj = __instance.GetType().GetField("playerMovement", bindingAttr)?.GetValue(__instance);
if (obj == null)
{
return;
}
object obj2 = obj.GetType().GetProperty("PlayerInfo", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj);
if (obj2 == null)
{
return;
}
object obj3 = obj2.GetType().GetProperty("PlayerId", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2);
if (obj3 == null)
{
return;
}
ulong guid = (ulong)(obj3.GetType().GetProperty("Guid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj3) ?? ((object)0uL));
Color val = Plugin.TeamColors[Plugin.GetTeam(guid)];
object? obj4 = __instance.GetType().GetField("skinColorProps", bindingAttr)?.GetValue(__instance);
MaterialPropertyBlock val2 = (MaterialPropertyBlock)((obj4 is MaterialPropertyBlock) ? obj4 : null);
if (val2 != null)
{
val2.SetColor("_Color", val);
object? obj5 = __instance.GetType().GetField("headRenderer", bindingAttr)?.GetValue(__instance);
object? obj6 = ((obj5 is Renderer) ? obj5 : null);
if (obj6 != null)
{
((Renderer)obj6).SetPropertyBlock(val2);
}
object? obj7 = __instance.GetType().GetField("bodyRenderer", bindingAttr)?.GetValue(__instance);
object? obj8 = ((obj7 is Renderer) ? obj7 : null);
if (obj8 != null)
{
((Renderer)obj8).SetPropertyBlock(val2);
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("SkinColorPatch: " + ex.Message));
}
}
}
[HarmonyPatch]
public class RegisterPlayerPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("GameManager"), "RegisterPlayer", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix()
{
TeamModeUi.RebuildPlayerDropdowns();
}
}
public static class ScoreboardTeamData
{
public static Dictionary<GameObject, ulong> EntryGuids = new Dictionary<GameObject, ulong>();
public static Dictionary<ulong, int> TotalMatchScores = new Dictionary<ulong, int>();
public static Dictionary<ulong, int> LastMatchScores = new Dictionary<ulong, int>();
}
[HarmonyPatch]
public class ScoreboardEntryPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("ScoreboardEntry"), "PopulateWith", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object __instance, object playerState)
{
//IL_0077: 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)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
try
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
ulong num = (ulong)(playerState.GetType().GetField("playerGuid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(playerState) ?? ((object)0uL));
object obj = ((__instance is Component) ? __instance : null);
GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)val != (Object)null)
{
ScoreboardTeamData.EntryGuids[val] = num;
}
if (Plugin.Enabled)
{
int team = Plugin.GetTeam(num);
Color val2 = Plugin.TeamColors[team];
object? obj2 = __instance.GetType().GetField("name", bindingAttr)?.GetValue(__instance);
TMP_Text val3 = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null);
if (!((Object)(object)val3 == (Object)null))
{
val3.text = val3.text + " <color=#" + ColorUtility.ToHtmlStringRGB(val2) + ">(" + Plugin.TeamNames[team] + ")</color>";
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("ScoreboardEntryPatch: " + ex.Message));
}
}
}
[HarmonyPatch]
public class ScoreboardRefreshPatch
{
private static readonly List<GameObject> _teamHeaders = new List<GameObject>();
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("Scoreboard"), "Refresh", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object __instance)
{
//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_0413: Unknown result type (might be due to invalid IL or missing references)
//IL_0458: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.Enabled)
{
return;
}
try
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
object? obj = __instance.GetType().GetField("entryParent", bindingFlags)?.GetValue(__instance);
Transform val = (Transform)((obj is Transform) ? obj : null);
if ((Object)(object)val == (Object)null)
{
return;
}
foreach (GameObject teamHeader in _teamHeaders)
{
if ((Object)(object)teamHeader != (Object)null)
{
Object.Destroy((Object)(object)teamHeader);
}
}
_teamHeaders.Clear();
List<GameObject> list = new List<GameObject>();
foreach (KeyValuePair<GameObject, ulong> entryGuid in ScoreboardTeamData.EntryGuids)
{
if ((Object)(object)entryGuid.Key == (Object)null)
{
list.Add(entryGuid.Key);
}
}
foreach (GameObject item2 in list)
{
ScoreboardTeamData.EntryGuids.Remove(item2);
}
Plugin.Log.LogInfo((object)$"\ud83d\udd04 Refresh — TotalMatchScores: {ScoreboardTeamData.TotalMatchScores.Count} entrées");
foreach (KeyValuePair<ulong, int> totalMatchScore in ScoreboardTeamData.TotalMatchScores)
{
Plugin.Log.LogInfo((object)$" guid={totalMatchScore.Key} total={totalMatchScore.Value} équipe={Plugin.TeamNames[Plugin.GetTeam(totalMatchScore.Key)]}");
}
Dictionary<int, int> teamScores = new Dictionary<int, int>();
Dictionary<int, List<(GameObject, int)>> dictionary = new Dictionary<int, List<(GameObject, int)>>();
for (int i = 0; i < val.childCount; i++)
{
GameObject gameObject = ((Component)val.GetChild(i)).gameObject;
if (gameObject.activeSelf && ScoreboardTeamData.EntryGuids.TryGetValue(gameObject, out var value))
{
int team = Plugin.GetTeam(value);
int value2;
int num = (ScoreboardTeamData.TotalMatchScores.TryGetValue(value, out value2) ? value2 : 0);
Plugin.Log.LogInfo((object)$"\ud83d\udc64 guid={value} équipe={Plugin.TeamNames[team]} total={num}");
if (!teamScores.ContainsKey(team))
{
teamScores[team] = 0;
}
teamScores[team] += num;
if (!dictionary.ContainsKey(team))
{
dictionary[team] = new List<(GameObject, int)>();
}
dictionary[team].Add((gameObject, num));
}
}
foreach (KeyValuePair<int, int> item3 in teamScores)
{
Plugin.Log.LogInfo((object)$"\ud83c\udfc6 Score total équipe {Plugin.TeamNames[item3.Key]} = {item3.Value}");
}
List<int> list2 = new List<int>(teamScores.Keys);
list2.Sort((int a, int b) => teamScores[b].CompareTo(teamScores[a]));
int num2 = 0;
foreach (int item4 in list2)
{
if (!dictionary.ContainsKey(item4) || dictionary[item4].Count == 0)
{
continue;
}
List<(GameObject, int)> list3 = dictionary[item4];
list3.Sort(((GameObject go, int matchScore) a, (GameObject go, int matchScore) b) => b.matchScore.CompareTo(a.matchScore));
int totalScore = teamScores[item4];
Color teamColor = Plugin.TeamColors[item4];
string teamName = Plugin.TeamNames[item4];
GameObject val2 = Object.Instantiate<GameObject>(list3[0].Item1, val);
((Object)val2).name = $"TM_TeamHeader_{item4}";
_teamHeaders.Add(val2);
SetupTeamHeader(val2, teamName, totalScore, teamColor, bindingFlags);
val2.transform.SetSiblingIndex(num2);
num2++;
foreach (var item5 in list3)
{
GameObject item = item5.Item1;
item.transform.SetSiblingIndex(num2);
TryColorEntryBackground(item, teamColor);
num2++;
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("ScoreboardRefreshPatch: " + ex.Message));
}
}
private static void SetupTeamHeader(GameObject header, string teamName, int totalScore, Color teamColor, BindingFlags flags)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
try
{
Image[] componentsInChildren = header.GetComponentsInChildren<Image>(true);
if (componentsInChildren.Length != 0)
{
((Graphic)componentsInChildren[0]).color = new Color(teamColor.r, teamColor.g, teamColor.b, 0.35f);
}
for (int i = 1; i < componentsInChildren.Length; i++)
{
((Graphic)componentsInChildren[i]).color = Color.clear;
}
TMP_Text[] componentsInChildren2 = header.GetComponentsInChildren<TMP_Text>(true);
foreach (TMP_Text val in componentsInChildren2)
{
val.text = "";
}
Component component = header.GetComponent(AccessTools.TypeByName("ScoreboardEntry"));
if (!((Object)(object)component == (Object)null))
{
object? obj = ((object)component).GetType().GetField("name", flags)?.GetValue(component);
TMP_Text val2 = (TMP_Text)((obj is TMP_Text) ? obj : null);
if ((Object)(object)val2 != (Object)null)
{
val2.text = string.Format("<b><color=#{0}>{1} {2} — {3} pts</color></b>", ColorUtility.ToHtmlStringRGB(teamColor), Lang.Get("Équipe", "Team"), teamName, totalScore);
val2.fontSize *= 1.1f;
}
object? obj2 = ((object)component).GetType().GetField("matchScore", flags)?.GetValue(component);
TMP_Text val3 = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null);
if ((Object)(object)val3 != (Object)null)
{
int num = totalScore;
val3.text = num.ToString();
}
}
}
catch
{
}
}
private static void TryColorEntryBackground(GameObject go, Color teamColor)
{
//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_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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)
try
{
Image[] componentsInChildren = go.GetComponentsInChildren<Image>(true);
if (componentsInChildren.Length != 0)
{
Color val = default(Color);
((Color)(ref val))..ctor(teamColor.r, teamColor.g, teamColor.b, 0.15f);
((Graphic)componentsInChildren[0]).color = Color.Lerp(((Graphic)componentsInChildren[0]).color, val, 0.4f);
}
}
catch
{
}
}
}
[HarmonyPatch]
public class TeamModeMenuPatch
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("MatchSetupRules"), "Initialize", (Type[])null, (Type[])null);
}
[HarmonyPostfix]
private static void Postfix(object __instance)
{
ScoreboardTeamData.LastMatchScores.Clear();
Plugin.Log.LogInfo((object)"\ud83d\uddfa\ufe0f Nouveau terrain → LastMatchScores réinitialisé");
try
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
object? obj = __instance.GetType().GetField("countdown", bindingAttr)?.GetValue(__instance);
Component val = (Component)((obj is Component) ? obj : null);
if ((Object)(object)val == (Object)null)
{
return;
}
Transform parent = val.transform.parent.parent.parent;
for (int i = 0; i < parent.childCount; i++)
{
if (((Object)parent.GetChild(i)).name == "Team Mode Header")
{
return;
}
}
GameObject gameObject = ((Component)val.transform.parent.GetChild(0)).gameObject;
object? obj2 = __instance.GetType().GetField("knockouts", bindingAttr)?.GetValue(__instance);
Component val2 = (Component)((obj2 is Component) ? obj2 : null);
Transform val3 = null;
Transform val4 = null;
for (int j = 0; j < parent.childCount; j++)
{
Transform child = parent.GetChild(j);
if (((Object)child).name == "Battle")
{
val3 = child;
}
if (((Object)child).name == "Battle Rules")
{
val4 = child;
}
}
if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val4 == (Object)null))
{
GameObject val5 = Object.Instantiate<GameObject>(((Component)val3).gameObject, parent);
((Object)val5).name = "Team Mode Header";
LocalizeStringEvent[] componentsInChildren = val5.GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val6 in componentsInChildren)
{
Object.Destroy((Object)(object)val6);
}
TMP_Text componentInChildren = val5.GetComponentInChildren<TMP_Text>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.text = Lang.Get("Mode Équipe", "Team Mode");
}
GameObject val7 = Object.Instantiate<GameObject>(((Component)val4).gameObject, parent);
((Object)val7).name = "Team Mode Rules";
for (int num = val7.transform.childCount - 1; num >= 0; num--)
{
Object.Destroy((Object)(object)((Component)val7.transform.GetChild(num)).gameObject);
}
TeamModeUi.Build(gameObject, (val2 != null) ? val2.gameObject : null, val7.transform);
Plugin.Log.LogInfo((object)"✓ Team Mode UI construite !");
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("TeamModeMenuPatch: " + ex.Message + "\n" + ex.StackTrace));
}
}
}
public static class TeamModeUi
{
private static GameObject? _sliderTemplate;
private static GameObject? _dropdownTemplate;
private static Transform? _container;
public static void Build(GameObject sliderTemplate, GameObject? dropdownTemplate, Transform container)
{
_sliderTemplate = sliderTemplate;
_dropdownTemplate = dropdownTemplate;
_container = container;
if ((Object)(object)dropdownTemplate != (Object)null)
{
AddToggle(dropdownTemplate, container, Lang.Get("Mode Équipe", "Team Mode"), Plugin.Enabled, delegate(bool v)
{
Plugin.Enabled = v;
Plugin.Log.LogInfo((object)("\ud83d\udd18 Team Mode " + (Plugin.Enabled ? "ACTIVÉ \ud83d\udfe2" : "DÉSACTIVÉ \ud83d\udd34")));
if (v)
{
RebuildPlayerDropdowns();
}
});
AddToggle(dropdownTemplate, container, Lang.Get("Tir ami", "Friendly Fire"), Plugin.FriendlyFireEnabled, delegate(bool v)
{
Plugin.FriendlyFireEnabled = v;
Plugin.Log.LogInfo((object)("\ud83d\udd2b Tir ami " + (Plugin.FriendlyFireEnabled ? "ACTIVÉ \ud83d\udfe2" : "DÉSACTIVÉ \ud83d\udd34")));
});
}
AddSlider(sliderTemplate, container, Lang.Get("Équipes", "Teams"), Plugin.TeamCount, 1, 4, 1, delegate(int v)
{
Plugin.TeamCount = v;
Plugin.Log.LogInfo((object)$"\ud83c\udff7\ufe0f Nombre d'équipes → {v}");
RebuildPlayerDropdowns();
});
RebuildPlayerDropdowns();
}
public static void RebuildPlayerDropdowns()
{
if ((Object)(object)_dropdownTemplate == (Object)null || (Object)(object)_container == (Object)null)
{
return;
}
for (int num = _container.childCount - 1; num >= 0; num--)
{
Transform child = _container.GetChild(num);
if (((Object)child).name.StartsWith("TM_Player_"))
{
Object.Destroy((Object)(object)((Component)child).gameObject);
}
}
List<(ulong, string)> connectedPlayers = GetConnectedPlayers();
Plugin.Log.LogInfo((object)$"\ud83d\udc65 {connectedPlayers.Count} joueur(s) trouvé(s) pour Team Mode");
foreach (var item3 in connectedPlayers)
{
ulong item = item3.Item1;
string item2 = item3.Item2;
ulong capturedGuid = item;
string capturedName = item2;
int team = Plugin.GetTeam(item);
AddPlayerDropdown(_dropdownTemplate, _container, item2, team, delegate(int v)
{
Plugin.PlayerTeams[capturedGuid] = v;
Plugin.Log.LogInfo((object)("\ud83d\udc64 " + capturedName + " → Equipe " + Plugin.TeamNames[v]));
});
}
}
private static List<(ulong guid, string name)> GetConnectedPlayers()
{
List<(ulong, string)> list = new List<(ulong, string)>();
try
{
Type type = AccessTools.TypeByName("GameManager");
object obj = type?.GetProperty("LocalPlayerInfo", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)?.GetValue(null);
if (obj != null)
{
object obj2 = obj.GetType().GetProperty("PlayerId", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj);
if (obj2 != null)
{
ulong item = (ulong)(obj2.GetType().GetProperty("Guid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2) ?? ((object)0uL));
string item2 = (string)(obj2.GetType().GetProperty("PlayerName", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj2) ?? "Local");
list.Add((item, item2));
}
}
object obj3 = type?.GetProperty("RemotePlayerPerConnectionId", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)?.GetValue(null);
if (obj3 != null)
{
object obj4 = obj3.GetType().GetProperty("Values")?.GetValue(obj3);
if (obj4 is IEnumerable enumerable)
{
foreach (object item5 in enumerable)
{
object obj5 = item5.GetType().GetProperty("PlayerId", BindingFlags.Instance | BindingFlags.Public)?.GetValue(item5);
if (obj5 != null)
{
ulong item3 = (ulong)(obj5.GetType().GetProperty("Guid", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj5) ?? ((object)0uL));
string item4 = (string)(obj5.GetType().GetProperty("PlayerName", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj5) ?? "Remote");
list.Add((item3, item4));
}
}
}
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("GetConnectedPlayers: " + ex.Message));
}
return list;
}
private static void SetRowHeight(GameObject go)
{
LayoutElement val = go.GetComponent<LayoutElement>();
if ((Object)(object)val == (Object)null)
{
val = go.AddComponent<LayoutElement>();
}
val.minHeight = 40f;
val.preferredHeight = 40f;
}
private static void AddToggle(GameObject dropdownTemplate, Transform parent, string label, bool defaultVal, Action<bool> onChange)
{
Action<bool> onChange2 = onChange;
GameObject val = Object.Instantiate<GameObject>(dropdownTemplate, parent);
((Object)val).name = "TM_Toggle_" + label;
SetRowHeight(val);
LocalizeStringEvent[] componentsInChildren = val.GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val2 in componentsInChildren)
{
Object.Destroy((Object)(object)val2);
}
TMP_Text[] componentsInChildren2 = val.GetComponentsInChildren<TMP_Text>(true);
if (componentsInChildren2.Length != 0)
{
componentsInChildren2[0].text = label;
}
TMP_Dropdown componentInChildren = val.GetComponentInChildren<TMP_Dropdown>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
componentInChildren.ClearOptions();
LocalizeStringEvent[] componentsInChildren3 = ((Component)componentInChildren).GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val3 in componentsInChildren3)
{
Object.Destroy((Object)(object)val3);
}
componentInChildren.AddOptions(new List<string>
{
Lang.Get("Oui", "Yes"),
Lang.Get("Non", "No")
});
((UnityEventBase)componentInChildren.onValueChanged).RemoveAllListeners();
componentInChildren.SetValueWithoutNotify((!defaultVal) ? 1 : 0);
((UnityEvent<int>)(object)componentInChildren.onValueChanged).AddListener((UnityAction<int>)delegate(int v)
{
onChange2(v == 0);
});
}
}
private static void AddSlider(GameObject template, Transform parent, string label, int defaultVal, int min, int max, int step, Action<int> onChange)
{
Action<int> onChange2 = onChange;
GameObject val = Object.Instantiate<GameObject>(template, parent);
((Object)val).name = "TM_Slider_" + label;
SetRowHeight(val);
LocalizeStringEvent[] componentsInChildren = val.GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val2 in componentsInChildren)
{
Object.Destroy((Object)(object)val2);
}
Slider slider = val.GetComponentInChildren<Slider>(true);
if ((Object)(object)slider == (Object)null)
{
return;
}
slider.minValue = min;
slider.maxValue = max;
slider.wholeNumbers = true;
((UnityEventBase)slider.onValueChanged).RemoveAllListeners();
slider.SetValueWithoutNotify((float)defaultVal);
TMP_Text[] componentsInChildren2 = val.GetComponentsInChildren<TMP_Text>(true);
TMP_Text val3 = ((componentsInChildren2.Length != 0) ? componentsInChildren2[0] : null);
TMP_Text valueText = ((componentsInChildren2.Length > 1) ? componentsInChildren2[1] : null);
if ((Object)(object)val3 != (Object)null)
{
val3.text = label;
}
if ((Object)(object)valueText != (Object)null)
{
valueText.text = defaultVal.ToString();
}
((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate(float v)
{
int num = Mathf.RoundToInt(v / (float)step) * step;
num = Mathf.Clamp(num, min, max);
if (Mathf.Abs(slider.value - (float)num) > 0.01f)
{
slider.SetValueWithoutNotify((float)num);
}
if ((Object)(object)valueText != (Object)null)
{
valueText.text = num.ToString();
}
onChange2(num);
});
}
private static void AddPlayerDropdown(GameObject dropdownTemplate, Transform parent, string playerName, int defaultTeam, Action<int> onChange)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
Action<int> onChange2 = onChange;
GameObject val = Object.Instantiate<GameObject>(dropdownTemplate, parent);
((Object)val).name = "TM_Player_" + playerName;
SetRowHeight(val);
LocalizeStringEvent[] componentsInChildren = val.GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val2 in componentsInChildren)
{
Object.Destroy((Object)(object)val2);
}
TMP_Text[] texts = val.GetComponentsInChildren<TMP_Text>(true);
if (texts.Length != 0)
{
texts[0].text = playerName;
((Graphic)texts[0]).color = Plugin.TeamColors[Mathf.Clamp(defaultTeam, 0, 3)];
}
TMP_Dropdown componentInChildren = val.GetComponentInChildren<TMP_Dropdown>(true);
if ((Object)(object)componentInChildren == (Object)null)
{
return;
}
componentInChildren.ClearOptions();
LocalizeStringEvent[] componentsInChildren2 = ((Component)componentInChildren).GetComponentsInChildren<LocalizeStringEvent>(true);
foreach (LocalizeStringEvent val3 in componentsInChildren2)
{
Object.Destroy((Object)(object)val3);
}
List<string> list = new List<string>();
for (int k = 0; k < Plugin.TeamCount; k++)
{
list.Add(Plugin.TeamNames[k]);
}
componentInChildren.AddOptions(list);
((UnityEventBase)componentInChildren.onValueChanged).RemoveAllListeners();
componentInChildren.SetValueWithoutNotify(Mathf.Clamp(defaultTeam, 0, Plugin.TeamCount - 1));
((UnityEvent<int>)(object)componentInChildren.onValueChanged).AddListener((UnityAction<int>)delegate(int v)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
onChange2(v);
if (texts.Length != 0)
{
((Graphic)texts[0]).color = Plugin.TeamColors[Mathf.Clamp(v, 0, 3)];
}
});
}
}
public static class Lang
{
public static bool IsFrench()
{
//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)
try
{
Locale selectedLocale = LocalizationSettings.SelectedLocale;
if ((Object)(object)selectedLocale == (Object)null)
{
return false;
}
LocaleIdentifier identifier = selectedLocale.Identifier;
return ((LocaleIdentifier)(ref identifier)).Code.StartsWith("fr");
}
catch
{
return CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "fr";
}
}
public static string Get(string fr, string en)
{
if (!IsFrench())
{
return en;
}
return fr;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ConstantExpectedAttribute : Attribute
{
public object? Min { get; set; }
public object? Max { get; set; }
}
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ExperimentalAttribute : Attribute
{
public string DiagnosticId { get; }
public string? UrlFormat { get; set; }
public ExperimentalAttribute(string diagnosticId)
{
DiagnosticId = diagnosticId;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class StringSyntaxAttribute : Attribute
{
public const string CompositeFormat = "CompositeFormat";
public const string DateOnlyFormat = "DateOnlyFormat";
public const string DateTimeFormat = "DateTimeFormat";
public const string EnumFormat = "EnumFormat";
public const string GuidFormat = "GuidFormat";
public const string Json = "Json";
public const string NumericFormat = "NumericFormat";
public const string Regex = "Regex";
public const string TimeOnlyFormat = "TimeOnlyFormat";
public const string TimeSpanFormat = "TimeSpanFormat";
public const string Uri = "Uri";
public const string Xml = "Xml";
public string Syntax { get; }
public object?[] Arguments { get; }
public StringSyntaxAttribute(string syntax)
{
Syntax = syntax;
Arguments = new object[0];
}
public StringSyntaxAttribute(string syntax, params object?[] arguments)
{
Syntax = syntax;
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class UnscopedRefAttribute : Attribute
{
}
}
namespace System.Runtime.Versioning
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresPreviewFeaturesAttribute : Attribute
{
public string? Message { get; }
public string? Url { get; set; }
public RequiresPreviewFeaturesAttribute()
{
}
public RequiresPreviewFeaturesAttribute(string? message)
{
Message = message;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public string ParameterName { get; }
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CollectionBuilderAttribute : Attribute
{
public Type BuilderType { get; }
public string MethodName { get; }
public CollectionBuilderAttribute(Type builderType, string methodName)
{
BuilderType = builderType;
MethodName = methodName;
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public const string RefStructs = "RefStructs";
public const string RequiredMembers = "RequiredMembers";
public string FeatureName { get; }
public bool IsOptional { get; set; }
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
}
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
public string[] Arguments { get; }
public InterpolatedStringHandlerArgumentAttribute(string argument)
{
Arguments = new string[1] { argument };
}
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
{
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerAttribute : Attribute
{
}
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal static class IsExternalInit
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ModuleInitializerAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class OverloadResolutionPriorityAttribute : Attribute
{
public int Priority { get; }
public OverloadResolutionPriorityAttribute(int priority)
{
Priority = priority;
}
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
[ExcludeFromCodeCoverage]
internal sealed class ParamCollectionAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiredMemberAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresLocationAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SkipLocalsInitAttribute : Attribute
{
}
}