Decompiled source of PlayerCount and PlayerList v0.9.1

PlayerCount_and_PlayerList/PlayerCount_and_PlayerList.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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("PlayerCount&List")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlayerCount&List")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e799282-a480-4f45-8291-596781251c13")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlayerCount_and_PlayerList;

[BepInPlugin("yazirushi.PlayerCount_and_PlayerList", "PlayerCount_and_PlayerList", "0.9.1")]
public class PlayerCount_and_PlayerList : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("yazirushi.PlayerCount_and_PlayerList");

	internal static ManualLogSource mls;

	public static ConfigEntry<float> UI_Text_X;

	public static ConfigEntry<float> UI_Text_Y;

	public static ConfigEntry<float> UI_FontSize;

	public static ConfigEntry<Color> UI_Color;

	public static ConfigEntry<KeyCode> ToggleKey;

	public static ConfigEntry<bool> DebugLog;

	public static Canvas canvas;

	public static TextMeshProUGUI text;

	public static int lobbyCount;

	public static int lobbyMax;

	public static void CreateUI()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("PlayerCount_and_PlayerListCanvas");
		canvas = val.AddComponent<Canvas>();
		canvas.renderMode = (RenderMode)0;
		canvas.scaleFactor = 1f;
		val.AddComponent<CanvasScaler>();
		val.AddComponent<GraphicRaycaster>();
		Object.DontDestroyOnLoad((Object)(object)val);
		GameObject val2 = new GameObject("PlayerCount_and_PlayerListText");
		val2.transform.SetParent(val.transform);
		text = val2.AddComponent<TextMeshProUGUI>();
		((TMP_Text)text).alignment = (TextAlignmentOptions)257;
		((TMP_Text)text).rectTransform.anchorMin = new Vector2(1f, 1f);
		((TMP_Text)text).rectTransform.anchorMax = new Vector2(1f, 1f);
		((TMP_Text)text).rectTransform.pivot = new Vector2(1f, 1f);
		if (DebugLog.Value)
		{
			mls.LogInfo((object)"CreateUI!");
		}
	}

	public static void UpdateUI()
	{
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)StartOfRound.Instance == (Object)null)
		{
			if (DebugLog.Value)
			{
				mls.LogError((object)"StartOfRound.Instance = null !");
			}
			return;
		}
		if (StartOfRound.Instance.allPlayerScripts == null)
		{
			if (DebugLog.Value)
			{
				mls.LogError((object)"StartOfRound.Instance.allPlayerScripts = null !");
			}
			return;
		}
		lobbyCount = StartOfRound.Instance.connectedPlayersAmount + 1;
		((TMP_Text)text).text = $"PlayerCount:{lobbyCount} \n\nPlayerList:";
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (((Object)(object)val != (Object)null && !string.IsNullOrWhiteSpace(val.playerUsername) && val.isPlayerDead && !val.isPlayerControlled) || ((Object)(object)val != (Object)null && !string.IsNullOrWhiteSpace(val.playerUsername) && !val.isPlayerDead && val.isPlayerControlled))
			{
				TextMeshProUGUI obj = text;
				((TMP_Text)obj).text = ((TMP_Text)obj).text + "\n" + val.playerUsername;
			}
			else if (DebugLog.Value)
			{
				mls.LogWarning((object)("excluding name:" + val.playerUsername));
			}
		}
		TMP_FontAsset preferredFont = LCFontUtil.GetPreferredFont();
		if ((Object)(object)preferredFont != (Object)null)
		{
			((TMP_Text)text).font = preferredFont;
			((TMP_Text)text).fontMaterial = LCFontUtil.GetFontMaterial();
		}
		((TMP_Text)text).fontSize = UI_FontSize.Value;
		((Graphic)text).color = UI_Color.Value;
		((TMP_Text)text).rectTransform.anchoredPosition = new Vector2(-10f + UI_Text_X.Value, -30f + UI_Text_Y.Value);
		if (DebugLog.Value)
		{
			mls.LogInfo((object)"UpdateUI!");
		}
	}

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Expected O, but got Unknown
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Expected O, but got Unknown
		UI_Text_X = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "UI Xoffset", 0f, new ConfigDescription("UI X-axis offset", (AcceptableValueBase)null, Array.Empty<object>()));
		UI_Text_Y = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "UI Yoffset", 0f, new ConfigDescription("UI Y-axis offset", (AcceptableValueBase)null, Array.Empty<object>()));
		UI_FontSize = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "UI FontSize", 26f, new ConfigDescription("UI text size", (AcceptableValueBase)null, Array.Empty<object>()));
		UI_Color = ((BaseUnityPlugin)this).Config.Bind<Color>("Settings", "UI Color", Color.green, new ConfigDescription("UI text color", (AcceptableValueBase)null, Array.Empty<object>()));
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Settings", "ToggleUI", (KeyCode)99, new ConfigDescription("Key to show/hide the UI", (AcceptableValueBase)null, Array.Empty<object>()));
		DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log", false, new ConfigDescription("Whether to output debug logs", (AcceptableValueBase)null, Array.Empty<object>()));
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"Starting PlayerCount_and_PlayerList...");
		harmony.PatchAll();
	}
}
[HarmonyPatch(typeof(StartOfRound), "Update")]
public class UI_Updater
{
	public static bool create_flag;

	public static float uiTimer;

	private static void Postfix()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		if (!create_flag)
		{
			create_flag = true;
			PlayerCount_and_PlayerList.CreateUI();
			((Behaviour)PlayerCount_and_PlayerList.canvas).enabled = false;
		}
		uiTimer += Time.deltaTime;
		if (uiTimer >= 1f && ((Behaviour)PlayerCount_and_PlayerList.canvas).enabled)
		{
			uiTimer = 0f;
			PlayerCount_and_PlayerList.UpdateUI();
		}
		if (Keyboard.current == null)
		{
			return;
		}
		Key? val = KeyUtil.ToInputSystemKey(PlayerCount_and_PlayerList.ToggleKey.Value);
		if (val.HasValue && ((ButtonControl)Keyboard.current[val.Value]).wasPressedThisFrame)
		{
			if (!((Behaviour)PlayerCount_and_PlayerList.canvas).enabled)
			{
				PlayerCount_and_PlayerList.UpdateUI();
			}
			((Behaviour)PlayerCount_and_PlayerList.canvas).enabled = !((Behaviour)PlayerCount_and_PlayerList.canvas).enabled;
			if (PlayerCount_and_PlayerList.DebugLog.Value)
			{
				PlayerCount_and_PlayerList.mls.LogInfo((object)$"changed : {((Behaviour)PlayerCount_and_PlayerList.canvas).enabled}");
			}
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
public class UI_Hider
{
	private static void Postfix()
	{
		if ((Object)(object)PlayerCount_and_PlayerList.canvas != (Object)null)
		{
			((Behaviour)PlayerCount_and_PlayerList.canvas).enabled = false;
			if (PlayerCount_and_PlayerList.DebugLog.Value)
			{
				PlayerCount_and_PlayerList.mls.LogInfo((object)"StartOfRound destroyed -> UI hide");
			}
		}
	}
}
public class LCFontUtil
{
	private static TMP_FontAsset cachedFont;

	private static Material cachedMat;

	public static TMP_FontAsset GetPreferredFont()
	{
		if ((Object)(object)cachedFont != (Object)null)
		{
			return cachedFont;
		}
		TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (TMP_FontAsset val in array)
		{
			if (((Object)val).name.Contains("3270"))
			{
				cachedFont = val;
				cachedMat = ((TMP_Asset)val).material;
				break;
			}
		}
		if ((Object)(object)cachedFont == (Object)null)
		{
			TextMeshProUGUI val2 = Object.FindObjectOfType<TextMeshProUGUI>();
			if ((Object)(object)val2 != (Object)null)
			{
				cachedFont = ((TMP_Text)val2).font;
				cachedMat = ((TMP_Text)val2).fontMaterial;
			}
		}
		return cachedFont;
	}

	public static Material GetFontMaterial()
	{
		return cachedMat;
	}
}
public static class KeyUtil
{
	public static Key? ToInputSystemKey(KeyCode keyCode)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (Enum.TryParse<Key>(((object)(KeyCode)(ref keyCode)).ToString(), out Key result))
		{
			return result;
		}
		return null;
	}
}