Decompiled source of DeathCounter v1.0.1

BepInEx/plugins/deathcounter.dll

Decompiled 2 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Mirror;
using TMPro;
using UnityEngine;
using YAPYAP;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("deathcounter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("deathcounter")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ca6473a1-f5a5-4c21-a7ef-0783d800e9a8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Xemotal;

public static class DeathCounterManager
{
	private static readonly Dictionary<int, int> DeathCounts = new Dictionary<int, int>();

	private static readonly Dictionary<int, string> RealNames = new Dictionary<int, string>();

	private static Pawn localPawn;

	private static Font gameFont;

	private static bool initialized;

	public static void Initialize()
	{
		if (!initialized)
		{
			initialized = true;
			Debug.Log((object)"[Xemotal] Death Counter initialisé.");
		}
	}

	private static int GetId(Pawn pawn)
	{
		if ((Object)(object)pawn == (Object)null)
		{
			return -1;
		}
		return pawn.PlayerNetId;
	}

	public static int GetDeathCount(Pawn pawn)
	{
		if ((Object)(object)pawn == (Object)null)
		{
			return 0;
		}
		return GetDeathCount(GetId(pawn));
	}

	private static int GetDeathCount(int id)
	{
		if (id < 0)
		{
			return 0;
		}
		if (DeathCounts.TryGetValue(id, out var value))
		{
			return value;
		}
		return 0;
	}

	public static void RegisterDeath(Pawn pawn)
	{
		if (!((Object)(object)pawn == (Object)null))
		{
			int id = GetId(pawn);
			if (id >= 0)
			{
				int deathCount = GetDeathCount(id);
				deathCount++;
				DeathCounts[id] = deathCount;
				string realName = GetRealName(pawn);
				Debug.Log((object)("[Xemotal] " + realName + " - mort n°" + deathCount));
			}
		}
	}

	private static string GetRealName(Pawn pawn)
	{
		if ((Object)(object)pawn == (Object)null)
		{
			return "";
		}
		int id = GetId(pawn);
		if (RealNames.TryGetValue(id, out var value))
		{
			return value;
		}
		string text = pawn.PlayerName;
		if (string.IsNullOrEmpty(text))
		{
			text = "Player";
		}
		RealNames[id] = text;
		return text;
	}

	public static void RegisterPawn(Pawn pawn)
	{
		if ((Object)(object)pawn == (Object)null)
		{
			return;
		}
		int id = GetId(pawn);
		if (id < 0)
		{
			return;
		}
		string playerName = pawn.PlayerName;
		if (!string.IsNullOrEmpty(playerName))
		{
			RealNames[id] = playerName;
		}
		if (!DeathCounts.ContainsKey(id))
		{
			DeathCounts[id] = 0;
		}
		if (!((NetworkBehaviour)pawn).isLocalPlayer)
		{
			return;
		}
		localPawn = pawn;
		PawnView view = pawn.View;
		if ((Object)(object)view != (Object)null)
		{
			TMP_Text playerNameText = view.PlayerNameText;
			if ((Object)(object)playerNameText != (Object)null && (Object)(object)playerNameText.font != (Object)null)
			{
				gameFont = playerNameText.font.sourceFontFile;
				if ((Object)(object)gameFont != (Object)null)
				{
					Debug.Log((object)("[Xemotal] Police du jeu récupérée : " + ((Object)gameFont).name));
				}
			}
		}
		Debug.Log((object)"[Xemotal] Joueur local enregistré pour le Death Counter.");
	}

	public static void OnGUI()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)localPawn == (Object)null) && ((NetworkBehaviour)localPawn).isLocalPlayer)
		{
			int deathCount = GetDeathCount(localPawn);
			GUIStyle val = new GUIStyle(GUI.skin.label);
			if ((Object)(object)gameFont != (Object)null)
			{
				val.font = gameFont;
			}
			val.alignment = (TextAnchor)1;
			val.fontSize = 28;
			val.fontStyle = (FontStyle)1;
			val.normal.textColor = Color.white;
			val.richText = false;
			GUIStyle val2 = new GUIStyle(val);
			val2.normal.textColor = Color.black;
			float num = (float)Screen.width * 0.5f;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(num - 200f + 2f, 20f, 400f, 50f);
			Rect val4 = default(Rect);
			((Rect)(ref val4))..ctor(num - 200f, 18f, 400f, 50f);
			string text = "Deaths: " + deathCount;
			GUI.Label(val3, text, val2);
			GUI.Label(val4, text, val);
		}
	}

	public static void Reset()
	{
		DeathCounts.Clear();
		RealNames.Clear();
		localPawn = null;
		gameFont = null;
		Debug.Log((object)"[Xemotal] Death Counter reset.");
	}
}
[BepInPlugin("Xemotal.DeathCounter", "Xemotal Death Counter", "1.0.0")]
public class XemotalDeathCounterPlugin : BaseUnityPlugin
{
	private Harmony harmony;

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		DeathCounterManager.Initialize();
		harmony = new Harmony("Xemotal.DeathCounter");
		harmony.PatchAll();
		Debug.Log((object)"[Xemotal] Death Counter chargé.");
	}

	private void OnGUI()
	{
		DeathCounterManager.OnGUI();
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		DeathCounterManager.Reset();
	}
}
[HarmonyPatch(typeof(Pawn), "OnIsDeadChanged")]
public static class PawnDeathPatch
{
	[HarmonyPostfix]
	private static void Postfix(Pawn __instance, bool oldValue, bool newValue)
	{
		if (!((Object)(object)__instance == (Object)null) && !oldValue && newValue)
		{
			Debug.Log((object)("[Xemotal] OnIsDeadChanged détecté pour " + __instance.PlayerName + " / local=" + ((NetworkBehaviour)__instance).isLocalPlayer + " / server=" + ((NetworkBehaviour)__instance).isServer));
			if (((NetworkBehaviour)__instance).isLocalPlayer)
			{
				DeathCounterManager.RegisterDeath(__instance);
			}
		}
	}
}
[HarmonyPatch(typeof(Pawn), "OnStartClient")]
public static class PawnStartClientPatch
{
	[HarmonyPostfix]
	private static void Postfix(Pawn __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			DeathCounterManager.RegisterPawn(__instance);
		}
	}
}
[HarmonyPatch(typeof(Pawn), "OnStartAuthority")]
public static class PawnAuthorityPatch
{
	[HarmonyPostfix]
	private static void Postfix(Pawn __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			DeathCounterManager.RegisterPawn(__instance);
		}
	}
}