Decompiled source of FullNameDisplay v1.1.2

Gafoneo.FullNameDisplay.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Gafoneo.FullNameDisplay")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+bfc9d2b38561bd660ae20f5d55860bd686b09feb")]
[assembly: AssemblyProduct("FullNameDisplay")]
[assembly: AssemblyTitle("Gafoneo.FullNameDisplay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 FullNameDisplay
{
	[BepInPlugin("Gafoneo.FullNameDisplay", "FullNameDisplay", "1.1.2")]
	public class FullNameDisplay : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("Gafoneo.FullNameDisplay").PatchAll();
			Logger.LogInfo((object)"Gafoneo.FullNameDisplay is loaded!");
		}
	}
	[HarmonyPatch]
	internal static class NameSanitizePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "SendNewPlayerValuesClientRpc")]
		public static bool Prefix4(ulong[] playerSteamIds, PlayerControllerB __instance)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
			{
				return false;
			}
			int value = val.Field("__rpc_exec_stage").GetValue<int>();
			if (value != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter value2 = val.Method("__beginSendClientRpc", new object[3]
				{
					956616685u,
					val2,
					(object)(RpcDelivery)0
				}).GetValue<FastBufferWriter>();
				bool flag = playerSteamIds != null;
				((FastBufferWriter)(ref value2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref value2)).WriteValueSafe<ulong>(playerSteamIds, default(ForPrimitives));
				}
				val.Method("__endSendClientRpc", new object[4]
				{
					value2,
					956616685u,
					val2,
					(object)(RpcDelivery)0
				}).GetValue();
			}
			if (value != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return false;
			}
			val.Field("__rpc_exec_stage").SetValue((object)0);
			for (int i = 0; i < playerSteamIds.Length; i++)
			{
				if (__instance.playersManager.allPlayerScripts[i].isPlayerControlled || __instance.playersManager.allPlayerScripts[i].isPlayerDead)
				{
					Friend val3 = new Friend(SteamId.op_Implicit(playerSteamIds[i]));
					string text = ((Friend)(ref val3)).Name;
					if (text.Length == 0)
					{
						text = "Nameless";
					}
					__instance.playersManager.allPlayerScripts[i].playerSteamId = playerSteamIds[i];
					__instance.playersManager.allPlayerScripts[i].playerUsername = text;
					((TMP_Text)__instance.playersManager.allPlayerScripts[i].usernameBillboardText).text = text;
					string text2 = text;
					int value3 = val.Method("GetNumberOfDuplicateNamesInLobby", Array.Empty<object>()).GetValue<int>();
					if (value3 > 0)
					{
						text2 = $"{text} #{value3}";
					}
					__instance.quickMenuManager.AddUserToPlayerList(playerSteamIds[i], text2, i);
					StartOfRound.Instance.mapScreen.radarTargets[i].name = text2;
				}
			}
			StartOfRound.Instance.StartTrackingAllPlayerVoices();
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
			{
				Traverse.Create((object)GameNetworkManager.Instance.localPlayerController).Field("updatePositionForNewlyJoinedClient").SetValue((object)true);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameNetworkManager), "SteamMatchmaking_OnLobbyMemberJoined")]
		public static bool Prefix5(Lobby lobby, Friend friend, GameNetworkManager __instance)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (instance.currentLobby.HasValue)
			{
				Lobby value = instance.currentLobby.Value;
				Friend[] array = ((Lobby)(ref value)).Members.ToArray();
				if (array != null)
				{
					for (int i = 0; i < array.Length; i++)
					{
						if (!__instance.steamIdsInLobby.Contains(array[i].Id))
						{
							__instance.steamIdsInLobby.Add(array[i].Id);
						}
					}
				}
			}
			Debug.Log((object)$"Player joined w steamId: {friend.Id}");
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				QuickMenuManager obj = Object.FindObjectOfType<QuickMenuManager>();
				if (obj != null)
				{
					obj.AddUserToPlayerList(SteamId.op_Implicit(friend.Id), ((Friend)(ref friend)).Name, StartOfRound.Instance.connectedPlayersAmount);
				}
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Gafoneo.FullNameDisplay";

		public const string PLUGIN_NAME = "FullNameDisplay";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}