Decompiled source of NexusTeams v1.0.1

plugins/NexusTeams.Plugin.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
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.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NexusRoles.API;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("NexusTeams.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+69b75ba145d41f2ff940e1f920dc2a46ebbc6bac")]
[assembly: AssemblyProduct("NexusTeams.Plugin")]
[assembly: AssemblyTitle("NexusTeams.Plugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace NexusTeams
{
	[BepInPlugin("com.stanis12.nexusteams", "NexusTeams", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class NexusTeamsPlugin : BaseUnityPlugin
	{
		internal static readonly Dictionary<string, TeamRole> Roles = new Dictionary<string, TeamRole>();

		internal static ConfigEntry<KeyCode> ToggleKey = null;

		internal static ConfigEntry<bool> ShowLocalPlayer = null;

		internal static ConfigEntry<float> PanelScale = null;

		internal static ConfigEntry<PanelPosition> Position = null;

		internal static bool Visible;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("NexusTeams", "Toggle key", (KeyCode)289, "Key to show or hide the teammate roles panel.");
			ShowLocalPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("NexusTeams", "Show local player", false, "Include your own role in the panel.");
			PanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("NexusTeams", "Panel scale", 1f, new ConfigDescription("Panel size multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.75f, 1.5f), Array.Empty<object>()));
			Position = ((BaseUnityPlugin)this).Config.Bind<PanelPosition>("NexusTeams", "Panel position", PanelPosition.Right, "Choose which side of the screen shows the panel.");
			harmony = new Harmony("com.stanis12.nexusteams");
			harmony.PatchAll();
			NexusRolesAPI.RoleAssigned += OnRoleAssigned;
			SceneManager.sceneLoaded += OnSceneLoaded;
			((Component)this).gameObject.AddComponent<TeamRolePanel>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"NexusTeams loaded (Thunderstore team: nexi).");
		}

		private void OnRoleAssigned(object? sender, RoleAssignedEventArgs args)
		{
			if (!SemiFunc.RunIsLevel() || SemiFunc.RunIsShop())
			{
				return;
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				string text = SemiFunc.PlayerGetSteamID(instance);
				string text2 = SemiFunc.PlayerGetName(instance);
				ApplyRole(text, text2, args.RoleId);
				if (PhotonNetwork.InRoom && (Object)(object)instance.photonView != (Object)null)
				{
					instance.photonView.RPC("ReceiveRole", (RpcTarget)3, new object[3] { text, text2, args.RoleId });
				}
			}
		}

		internal static void ApplyRole(string id, string name, int roleId)
		{
			string[] forCurrentLanguage = RoleNames.ForCurrentLanguage;
			if (!string.IsNullOrEmpty(id) && roleId > 0 && roleId < forCurrentLanguage.Length)
			{
				Roles[id] = new TeamRole(id, name, forCurrentLanguage[roleId]);
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Roles.Clear();
			Visible = false;
		}

		private void OnDestroy()
		{
			NexusRolesAPI.RoleAssigned -= OnRoleAssigned;
			SceneManager.sceneLoaded -= OnSceneLoaded;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	internal enum PanelPosition
	{
		Left,
		Right
	}
	internal static class RoleNames
	{
		private static readonly string[][] Translations = new string[3][]
		{
			new string[14]
			{
				"", "Runner", "Tank", "Gambler", "Strongman", "Ranged Looter", "Athletic", "Mage", "Reaper", "Scout",
				"Regular", "Engineer", "Acrobat", "Savior"
			},
			new string[14]
			{
				"", "Бегун", "Танк", "Игрок", "Силач", "Дальнобойщик", "Атлет", "Маг", "Жнец", "Разведчик",
				"Обычный", "Инженер", "Акробат", "Спаситель"
			},
			new string[14]
			{
				"", "Бігун", "Танк", "Гравець", "Силач", "Далекобійник", "Атлет", "Маг", "Жнець", "Розвідник",
				"Звичайний", "Інженер", "Акробат", "Рятівник"
			}
		};

		internal static string[] ForCurrentLanguage
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Invalid comparison between Unknown and I4
				SystemLanguage systemLanguage = Application.systemLanguage;
				if ((int)systemLanguage != 30)
				{
					if ((int)systemLanguage == 38)
					{
						return Translations[2];
					}
					return Translations[0];
				}
				return Translations[1];
			}
		}

		internal static string PanelTitle
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Invalid comparison between Unknown and I4
				SystemLanguage systemLanguage = Application.systemLanguage;
				if ((int)systemLanguage != 30)
				{
					if ((int)systemLanguage == 38)
					{
						return "Ролі";
					}
					return "Roles";
				}
				return "Роли";
			}
		}

		internal static string WaitingText
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Invalid comparison between Unknown and I4
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Invalid comparison between Unknown and I4
				SystemLanguage systemLanguage = Application.systemLanguage;
				if ((int)systemLanguage != 30)
				{
					if ((int)systemLanguage == 38)
					{
						return "Очікування на ролі…";
					}
					return "Waiting for roles…";
				}
				return "Ожидание ролей…";
			}
		}

		internal unsafe static string ToggleText(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			SystemLanguage systemLanguage = Application.systemLanguage;
			if ((int)systemLanguage != 30)
			{
				if ((int)systemLanguage == 38)
				{
					return "Показати/сховати: " + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
				}
				return "Show/hide: " + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			}
			return "Показать/скрыть: " + ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
		}
	}
	internal sealed class TeamRole
	{
		internal readonly string Id;

		internal readonly string Name;

		internal readonly string Role;

		internal TeamRole(string id, string name, string role)
		{
			Id = id;
			Name = name;
			Role = role;
		}
	}
	internal sealed class RoleRelay : MonoBehaviour
	{
		[PunRPC]
		public void ReceiveRole(string id, string name, int roleId)
		{
			NexusTeamsPlugin.ApplyRole(id, name, roleId);
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Awake")]
	internal static class AvatarRelayPatch
	{
		private static void Postfix(PlayerAvatar __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<RoleRelay>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<RoleRelay>();
			}
		}
	}
	internal sealed class TeamRolePanel : MonoBehaviour
	{
		private GUIStyle title;

		private GUIStyle item;

		private GUIStyle hint;

		private Texture2D panel;

		private bool stylesReady;

		private void Awake()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			panel = new Texture2D(1, 1);
			panel.SetPixel(0, 0, new Color(0.025f, 0.035f, 0.05f, 0.82f));
			panel.Apply();
		}

		private void Update()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if ((!((Object)(object)ChatManager.instance != (Object)null) || !ChatManager.instance.chatActive) && Input.GetKeyDown(NexusTeamsPlugin.ToggleKey.Value))
			{
				NexusTeamsPlugin.Visible = !NexusTeamsPlugin.Visible;
			}
		}

		private void OnGUI()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			if (!NexusTeamsPlugin.Visible || !SemiFunc.RunIsLevel() || SemiFunc.RunIsShop())
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).name.ToLowerInvariant().Contains("menu"))
			{
				EnsureStyles();
				float value = NexusTeamsPlugin.PanelScale.Value;
				float num = 238f * value;
				TeamRole[] array = (from r in NexusTeamsPlugin.Roles.Values
					where NexusTeamsPlugin.ShowLocalPlayer.Value || (Object)(object)PlayerAvatar.instance == (Object)null || r.Id != SemiFunc.PlayerGetSteamID(PlayerAvatar.instance)
					orderby r.Name
					select r).ToArray();
				float num2 = (float)(60 + array.Length * 25) * value;
				float num3 = ((NexusTeamsPlugin.Position.Value == PanelPosition.Left) ? (18f * value) : ((float)Screen.width - num - 18f * value));
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(num3, (float)Screen.height * 0.34f, num, num2);
				GUI.DrawTexture(val, (Texture)(object)panel);
				GUI.Label(new Rect(((Rect)(ref val)).x + 12f * value, ((Rect)(ref val)).y + 7f * value, num - 20f * value, 25f * value), RoleNames.PanelTitle, title);
				if (array.Length == 0)
				{
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f * value, ((Rect)(ref val)).y + 34f * value, num - 20f * value, 20f * value), RoleNames.WaitingText, hint);
				}
				for (int num4 = 0; num4 < array.Length; num4++)
				{
					GUI.Label(new Rect(((Rect)(ref val)).x + 12f * value, ((Rect)(ref val)).y + (float)(32 + num4 * 25) * value, num - 20f * value, 23f * value), array[num4].Name + "  ·  " + array[num4].Role, item);
				}
				GUI.Label(new Rect(((Rect)(ref val)).x + 12f * value, ((Rect)(ref val)).yMax - 19f * value, num - 20f * value, 16f * value), RoleNames.ToggleText(NexusTeamsPlugin.ToggleKey.Value), hint);
			}
		}

		private void EnsureStyles()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0057: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			if (!stylesReady)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					fontSize = 17,
					fontStyle = (FontStyle)1
				};
				val.normal.textColor = new Color(0.48f, 0.84f, 1f);
				title = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14
				};
				val2.normal.textColor = Color.white;
				item = val2;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 11
				};
				val3.normal.textColor = new Color(0.7f, 0.74f, 0.8f);
				hint = val3;
				stylesReady = true;
			}
		}
	}
}