Decompiled source of CustomNicknamePlus v1.0.1

Antro.CustomNicknamePlus.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.IL2CPP;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SteamworksNative;
using TMPro;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Antro.CustomNickname+")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Antro.CustomNickname+")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Antro.CustomNickname+")]
[assembly: AssemblyTitle("Antro.CustomNickname+")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Antro.CustomNickname
{
	[BepInPlugin("Antro.CustomNicknamePlus", "Antro Custom Nickname+", "1.0.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public static string SavePath;

		public static bool HasColorMod;

		public override void Load()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			SavePath = Path.Combine(Paths.ConfigPath, "AntroNicknames.txt");
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Antro.ColorEnabler"))
			{
				HasColorMod = true;
				((BasePlugin)this).Log.LogInfo((object)"Color Mod detected!");
			}
			ClassInjector.RegisterTypeInIl2Cpp<NicknameController>();
			GameObject val = new GameObject("AntroNickname_UI");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<NicknameController>();
			((BasePlugin)this).Log.LogInfo((object)"Antro Custom Nickname+ v1.0.0.0 Loaded");
		}
	}
	public class NicknameController : MonoBehaviour
	{
		private bool _isOpen = false;

		private Rect _windowRect = new Rect(100f, 100f, 750f, 500f);

		private Vector2 _scrollPlayers;

		private ulong _selectedPlayerId = 0uL;

		private string _selectedPlayerName = "None";

		private string _inputNickname = "";

		private Dictionary<ulong, string> _savedNicknames = new Dictionary<ulong, string>();

		private Dictionary<ulong, GameObject> _activeLabels = new Dictionary<ulong, GameObject>();

		private TMP_FontAsset _gameFont;

		private GUIStyle _headerStyle;

		private bool _stylesInit = false;

		private const int MAX_VISIBLE_CHARS = 25;

		public NicknameController(IntPtr ptr)
			: base(ptr)
		{
		}//IL_001c: 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)


		private void Start()
		{
			LoadSaves();
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)287))
			{
				_isOpen = !_isOpen;
				if (_isOpen)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
				else if ((Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance != (Object)null && MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.Count > 0)
				{
					Cursor.lockState = (CursorLockMode)1;
					Cursor.visible = false;
				}
			}
			if ((Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance != (Object)null && MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers != null)
			{
				Enumerator<ulong, MonoBehaviourPublicCSstReshTrheObplBojuUnique> enumerator = MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.GetEnumerator();
				while (enumerator.MoveNext())
				{
					KeyValuePair<ulong, MonoBehaviourPublicCSstReshTrheObplBojuUnique> current = enumerator.Current;
					ulong key = current.Key;
					MonoBehaviourPublicCSstReshTrheObplBojuUnique value = current.Value;
					if (_savedNicknames.ContainsKey(key) && (!_activeLabels.ContainsKey(key) || (Object)(object)_activeLabels[key] == (Object)null) && (Object)(object)value != (Object)null && !value.dead)
					{
						Create3DText(key, _savedNicknames[key]);
					}
				}
				if ((Object)(object)Camera.main != (Object)null)
				{
					foreach (KeyValuePair<ulong, GameObject> activeLabel in _activeLabels)
					{
						GameObject value2 = activeLabel.Value;
						if ((Object)(object)value2 != (Object)null)
						{
							value2.transform.LookAt(((Component)Camera.main).transform);
							value2.transform.Rotate(0f, 180f, 0f);
						}
					}
				}
			}
			CleanUp();
		}

		private void Create3DText(ulong playerId, string text)
		{
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance == (Object)null || !MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.ContainsKey(playerId))
			{
				return;
			}
			MonoBehaviourPublicCSstReshTrheObplBojuUnique val = MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers[playerId];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform val2 = FindHead(((Component)val).transform);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			if (_activeLabels.ContainsKey(playerId) && (Object)(object)_activeLabels[playerId] != (Object)null)
			{
				Object.Destroy((Object)(object)_activeLabels[playerId]);
			}
			if ((Object)(object)_gameFont == (Object)null)
			{
				Type type = Type.GetType("TMPro.TMP_FontAsset, Unity.TextMeshPro");
				if (type == (Type)null)
				{
					type = Type.GetType("TMPro.TMP_FontAsset");
				}
				if (type != (Type)null)
				{
					Il2CppReferenceArray<Object> val3 = Resources.FindObjectsOfTypeAll(type);
					if (val3 != null && ((Il2CppArrayBase<Object>)(object)val3).Count > 0)
					{
						_gameFont = ((Il2CppObjectBase)((Il2CppArrayBase<Object>)(object)val3)[0]).TryCast<TMP_FontAsset>();
					}
				}
			}
			GameObject val4 = new GameObject("CustomNick_" + playerId);
			val4.transform.SetParent(val2);
			val4.transform.localPosition = new Vector3(0f, 5f, 0f);
			val4.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
			TextMeshPro val5 = val4.AddComponent<TextMeshPro>();
			if ((Object)(object)_gameFont != (Object)null)
			{
				((TMP_Text)val5).font = _gameFont;
			}
			((TMP_Text)val5).text = text;
			((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val5).fontSize = 28f;
			((TMP_Text)val5).richText = true;
			((TMP_Text)val5).rectTransform.sizeDelta = new Vector2(50f, 10f);
			((TMP_Text)val5).enableWordWrapping = false;
			_activeLabels[playerId] = val4;
		}

		private void OnGUI()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (_isOpen)
			{
				if (!_stylesInit)
				{
					_headerStyle = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontStyle = (FontStyle)1,
						fontSize = 14
					};
					_headerStyle.normal.textColor = Color.yellow;
					_stylesInit = true;
				}
				GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f, 0.95f);
				GUI.contentColor = Color.white;
				_windowRect = GUI.Window(9001, _windowRect, WindowFunction.op_Implicit((Action<int>)DrawWindow), "CustomNickname+ by Antropomeda 1.0.0.0");
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(250f) });
			GUILayout.Label("Players List", _headerStyle, Array.Empty<GUILayoutOption>());
			_scrollPlayers = GUILayout.BeginScrollView(_scrollPlayers, GUIStyle.op_Implicit("box"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(400f) });
			if ((Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance != (Object)null && MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers != null)
			{
				ulong steamID = MonoBehaviourPublicObInUIgaStCSBoStcuCSUnique.Instance.field_Private_CSteamID_0.m_SteamID;
				Enumerator<ulong, MonoBehaviourPublicCSstReshTrheObplBojuUnique> enumerator = MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.GetEnumerator();
				while (enumerator.MoveNext())
				{
					KeyValuePair<ulong, MonoBehaviourPublicCSstReshTrheObplBojuUnique> current = enumerator.Current;
					ulong key = current.Key;
					string text = "Unk";
					try
					{
						text = SteamFriends.GetFriendPersonaName(new CSteamID(key));
					}
					catch
					{
					}
					bool flag = key == steamID;
					bool flag2 = _savedNicknames.ContainsKey(key);
					if (key == _selectedPlayerId)
					{
						GUI.backgroundColor = Color.green;
					}
					else if (flag)
					{
						GUI.backgroundColor = Color.gray;
					}
					else if (flag2)
					{
						GUI.backgroundColor = new Color(0.2f, 0.5f, 0.8f);
					}
					else
					{
						GUI.backgroundColor = new Color(0.2f, 0.2f, 0.2f);
					}
					if (GUILayout.Button(text + (flag2 ? " [*]" : ""), Array.Empty<GUILayoutOption>()))
					{
						_selectedPlayerId = key;
						_selectedPlayerName = text;
						if (_savedNicknames.ContainsKey(key))
						{
							_inputNickname = _savedNicknames[key];
						}
						else
						{
							_inputNickname = "";
						}
					}
				}
			}
			GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f);
			GUILayout.EndScrollView();
			GUILayout.EndVertical();
			GUILayout.Space(10f);
			GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
			if (_selectedPlayerId != 0)
			{
				GUILayout.Label("Editing: " + _selectedPlayerName, _headerStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(5f);
				GUILayout.Label("Formatting (Tags do not count to limit):", Array.Empty<GUILayoutOption>());
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("<b>B</b>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
				{
					AddTag("b");
				}
				if (GUILayout.Button("<i>I</i>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
				{
					AddTag("i");
				}
				if (GUILayout.Button("<u>U</u>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
				{
					AddTag("u");
				}
				if (GUILayout.Button("<s>S</s>", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
				{
					AddTag("s");
				}
				if (Plugin.HasColorMod && GUILayout.Button("Color", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
				{
					AddTag("color=red");
				}
				GUILayout.EndHorizontal();
				GUILayout.Label($"Text (Visible Limit: {GetVisibleLength(_inputNickname)}/{25}):", Array.Empty<GUILayoutOption>());
				string text2 = GUILayout.TextField(_inputNickname, 200, Array.Empty<GUILayoutOption>());
				text2 = text2.Replace("\n", "").Replace("\r", "");
				if (!text2.ToLower().Contains("<size"))
				{
					if (GetVisibleLength(text2) <= 25)
					{
						_inputNickname = text2;
					}
					else if (text2.Length < _inputNickname.Length)
					{
						_inputNickname = text2;
					}
				}
				if (!Plugin.HasColorMod)
				{
					GUI.contentColor = Color.red;
					GUILayout.Label("Color Mod missing! Colors disabled.", Array.Empty<GUILayoutOption>());
					GUI.contentColor = Color.white;
				}
				GUILayout.Space(20f);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUI.backgroundColor = Color.green;
				if (GUILayout.Button("APPLY TEXT", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
				{
					_savedNicknames[_selectedPlayerId] = _inputNickname;
					Create3DText(_selectedPlayerId, _inputNickname);
					SaveData();
				}
				GUI.backgroundColor = Color.red;
				if (GUILayout.Button("REMOVE", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
				{
					RemoveNickname(_selectedPlayerId);
					_inputNickname = "";
				}
				GUI.backgroundColor = new Color(0.1f, 0.1f, 0.1f);
				GUILayout.EndHorizontal();
			}
			else
			{
				GUILayout.Label("Select a player to edit", _headerStyle, Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndVertical();
			GUILayout.EndHorizontal();
		}

		private int GetVisibleLength(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return 0;
			}
			string text2 = Regex.Replace(text, "<.*?>", "");
			return text2.Length;
		}

		private void AddTag(string tag)
		{
			string text = (tag.Contains("=") ? tag.Split(new char[1] { '=' })[0] : tag);
			string inputNickname = _inputNickname + "<" + tag + ">TEXT</" + text + ">";
			_inputNickname = inputNickname;
		}

		private void RemoveNickname(ulong playerId)
		{
			if (_savedNicknames.ContainsKey(playerId))
			{
				_savedNicknames.Remove(playerId);
				SaveData();
			}
			if (_activeLabels.ContainsKey(playerId))
			{
				if ((Object)(object)_activeLabels[playerId] != (Object)null)
				{
					Object.Destroy((Object)(object)_activeLabels[playerId]);
				}
				_activeLabels.Remove(playerId);
			}
		}

		private void SaveData()
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<ulong, string> savedNickname in _savedNicknames)
			{
				list.Add($"{savedNickname.Key}:{savedNickname.Value}");
			}
			File.WriteAllLines(Plugin.SavePath, list);
		}

		private void LoadSaves()
		{
			if (!File.Exists(Plugin.SavePath))
			{
				return;
			}
			try
			{
				string[] array = File.ReadAllLines(Plugin.SavePath);
				string[] array2 = array;
				foreach (string text in array2)
				{
					int num = text.IndexOf(':');
					if (num > 0)
					{
						string s = text.Substring(0, num);
						string value = text.Substring(num + 1);
						if (ulong.TryParse(s, out var result))
						{
							_savedNicknames[result] = value;
						}
					}
				}
			}
			catch
			{
			}
		}

		private void CleanUp()
		{
			List<ulong> list = new List<ulong>();
			foreach (KeyValuePair<ulong, GameObject> activeLabel in _activeLabels)
			{
				if ((Object)(object)activeLabel.Value == (Object)null)
				{
					list.Add(activeLabel.Key);
				}
				else if ((Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance != (Object)null && !MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.ContainsKey(activeLabel.Key))
				{
					Object.Destroy((Object)(object)activeLabel.Value);
					list.Add(activeLabel.Key);
				}
			}
			foreach (ulong item in list)
			{
				_activeLabels.Remove(item);
			}
		}

		private Transform FindHead(Transform current)
		{
			if (((Object)current).name.ToLower().Contains("head") || ((Object)current).name == "Spine.002")
			{
				return current;
			}
			for (int i = 0; i < current.childCount; i++)
			{
				Transform val = FindHead(current.GetChild(i));
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}
	}
}