Decompiled source of FullNameDisplay v1.0.2

FullNameDisplay.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
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: AssemblyTitle("FullNameDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FullNameDisplay")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3870f448-9e7d-4b93-92b8-4fbb171b48ef")]
[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 NameFix
{
	[BepInPlugin("Gafoneo.FullNameDisplay", "FullNameDisplay", "1.0.2")]
	public class NameFix : BaseUnityPlugin
	{
		internal const string Name = "FullNameDisplay";

		internal const string Author = "Gafoneo";

		internal const string ID = "Gafoneo.FullNameDisplay";

		internal const string Version = "1.0.2";

		internal ManualLogSource mls;

		public void Awake()
		{
			//IL_0005: 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)
			Harmony val = new Harmony("Gafoneo.FullNameDisplay");
			mls = Logger.CreateLogSource("Gafoneo.FullNameDisplay");
			mls.LogInfo((object)"Applying Harmony patches");
			val.PatchAll(Assembly.GetExecutingAssembly());
			int num = 0;
			foreach (MethodBase patchedMethod in val.GetPatchedMethods())
			{
				mls.LogInfo((object)("Patched " + patchedMethod.DeclaringType.Name + "." + patchedMethod.Name));
				num++;
			}
			mls.LogInfo((object)$"{num} patches applied");
		}
	}
}
namespace NameFix.Patches
{
	[HarmonyPatch]
	internal static class NameSanitizePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "NoPunctuation")]
		public static bool Prefix1(ref string __result, string input)
		{
			__result = input;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameNetworkManager), "NoPunctuation")]
		public static bool Prefix2(ref string __result, string input)
		{
			__result = input;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StartOfRound), "NoPunctuation")]
		public static bool Prefix3(ref string __result, string input)
		{
			__result = input;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerControllerB), "SendNewPlayerValuesClientRpc")]
		public static bool Prefix4(ulong[] playerSteamIds, PlayerControllerB __instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0093: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return false;
			}
			int value = Traverse.Create((object)__instance).Field("__rpc_exec_stage").GetValue<int>();
			if (value != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter value2 = Traverse.Create((object)__instance).Method("__beginSendClientRpc", new object[3]
				{
					956616685u,
					val,
					(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));
				}
				AccessTools.Method(typeof(NetworkBehaviour), "__endSendClientRpc", (Type[])null, (Type[])null).Invoke(__instance, new object[4]
				{
					value2,
					956616685u,
					val,
					(object)(RpcDelivery)0
				});
			}
			if (value != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return false;
			}
			for (int i = 0; i < playerSteamIds.Length; i++)
			{
				StartOfRound value3 = Traverse.Create((object)__instance).Field("playersManager").GetValue<StartOfRound>();
				if (value3.allPlayerScripts[i].isPlayerControlled || value3.allPlayerScripts[i].isPlayerDead)
				{
					Traverse obj = Traverse.Create((object)__instance);
					object[] array = new object[1];
					Friend val2 = new Friend(SteamId.op_Implicit(playerSteamIds[i]));
					array[0] = ((Friend)(ref val2)).Name;
					string text = obj.Method("NoPunctuation", array).GetValue<string>();
					if (text == string.Empty || text.Length == 0)
					{
						text = "Nameless";
					}
					else if (text.Length <= 2)
					{
						text += "0";
					}
					value3.allPlayerScripts[i].playerSteamId = playerSteamIds[i];
					value3.allPlayerScripts[i].playerUsername = text;
					((TMP_Text)value3.allPlayerScripts[i].usernameBillboardText).text = text;
					string text2 = text;
					int value4 = Traverse.Create((object)__instance).Method("GetNumberOfDuplicateNamesInLobby", Array.Empty<object>()).GetValue<int>();
					if (value4 > 0)
					{
						text2 = $"{text}{value4}";
					}
					Traverse.Create((object)__instance).Field("quickMenuManager").GetValue<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)__instance).Field("GameNetworkManager.Instance.localPlayerController.updatePositionForNewlyJoinedClient").SetValue((object)true);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameNetworkManager), "SteamMatchmaking_OnLobbyMemberJoined")]
		public static bool Prefix5(Lobby lobby, Friend friend, GameNetworkManager __instance)
		{
			//IL_009c: 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_0021: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (GameNetworkManager.Instance.currentLobby.HasValue)
			{
				Lobby value = GameNetworkManager.Instance.currentLobby.Value;
				Friend[] array = ((Lobby)(ref value)).Members.ToArray();
				if (array != null)
				{
					for (int i = 0; i < array.Length; i++)
					{
						List<SteamId> value2 = Traverse.Create((object)__instance).Field("steamIdsInLobby").GetValue<List<SteamId>>();
						if (!value2.Contains(array[i].Id))
						{
							value2.Add(array[i].Id);
						}
					}
				}
			}
			Traverse.Create((object)__instance).Method("Debug.Log", new object[1] { $"Player joined w steamId: {friend.Id}" });
			if ((Object)(object)StartOfRound.Instance != (Object)null)
			{
				QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
				if ((Object)(object)val != (Object)null)
				{
					string value3 = Traverse.Create((object)__instance).Method("NoPunctuation", new object[1] { ((Friend)(ref friend)).Name }).GetValue<string>();
					val.AddUserToPlayerList(SteamId.op_Implicit(friend.Id), value3, StartOfRound.Instance.connectedPlayersAmount);
				}
			}
			return false;
		}
	}
}