Decompiled source of LobbyInfo v1.3.1

LobbyInfo.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using ExitGames.Client.Photon;
using MelonLoader;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(LobbyInfoMod), "Lobby Info", "1.1.7", "CowboyHatVR", null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LobbyHUD")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LobbyHUD")]
[assembly: AssemblyTitle("LobbyHUD")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
public class LobbyInfoMod : MelonMod
{
	private GameObject vrHudRoot;

	private TextMesh vrLine1;

	private TextMesh vrLine2;

	private Camera cachedCamera;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("Lobby Info loaded");
	}

	public override void OnUpdate()
	{
		EnsureVrHudExists();
		UpdateVrHud();
	}

	private void EnsureVrHudExists()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_009a: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Expected O, but got Unknown
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		Camera mainCamera = GetMainCamera();
		if (!((Object)(object)mainCamera == (Object)null) && (!((Object)(object)vrHudRoot != (Object)null) || !((Object)(object)cachedCamera == (Object)(object)mainCamera)))
		{
			if ((Object)(object)vrHudRoot != (Object)null)
			{
				Object.Destroy((Object)(object)vrHudRoot);
			}
			cachedCamera = mainCamera;
			vrHudRoot = new GameObject("LobbyInfo_VRHUD");
			Object.DontDestroyOnLoad((Object)(object)vrHudRoot);
			vrHudRoot.transform.SetParent(((Component)mainCamera).transform, false);
			vrHudRoot.transform.localPosition = new Vector3(0f, -0.14f, 0.62f);
			vrHudRoot.transform.localRotation = Quaternion.identity;
			vrHudRoot.transform.localScale = Vector3.one * 0.008f;
			GameObject val = new GameObject("VRLine1");
			val.transform.SetParent(vrHudRoot.transform, false);
			val.transform.localPosition = new Vector3(0f, 0.34f, 0f);
			vrLine1 = val.AddComponent<TextMesh>();
			vrLine1.text = "";
			vrLine1.fontSize = 80;
			vrLine1.characterSize = 0.1f;
			vrLine1.anchor = (TextAnchor)4;
			vrLine1.alignment = (TextAlignment)1;
			vrLine1.color = Color.white;
			GameObject val2 = new GameObject("VRLine2");
			val2.transform.SetParent(vrHudRoot.transform, false);
			val2.transform.localPosition = new Vector3(0f, -0.14f, 0f);
			vrLine2 = val2.AddComponent<TextMesh>();
			vrLine2.text = "";
			vrLine2.fontSize = 92;
			vrLine2.characterSize = 0.1f;
			vrLine2.anchor = (TextAnchor)4;
			vrLine2.alignment = (TextAlignment)1;
			vrLine2.color = Color.white;
			ApplyTextMaterial(vrLine1);
			ApplyTextMaterial(vrLine2);
			MelonLogger.Msg("VR HUD created");
		}
	}

	private void ApplyTextMaterial(TextMesh textMesh)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)textMesh == (Object)null)
		{
			return;
		}
		MeshRenderer component = ((Component)textMesh).GetComponent<MeshRenderer>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		Font builtinResource = Resources.GetBuiltinResource<Font>("Arial.ttf");
		if ((Object)(object)builtinResource != (Object)null)
		{
			textMesh.font = builtinResource;
			((Renderer)component).material = new Material(builtinResource.material);
		}
		((Renderer)component).enabled = true;
		((Renderer)component).receiveShadows = false;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		if ((Object)(object)((Renderer)component).material != (Object)null)
		{
			((Renderer)component).material.color = Color.white;
			Shader val = Shader.Find("GUI/Text Shader");
			if ((Object)(object)val != (Object)null)
			{
				((Renderer)component).material.shader = val;
			}
		}
	}

	private void UpdateVrHud()
	{
		if (!((Object)(object)vrHudRoot == (Object)null) && !((Object)(object)vrLine1 == (Object)null) && !((Object)(object)vrLine2 == (Object)null))
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null)
			{
				Room currentRoom = PhotonNetwork.CurrentRoom;
				int maxPlayers = ((currentRoom.MaxPlayers > 0) ? currentRoom.MaxPlayers : 10);
				vrLine1.text = "Lobby: " + currentRoom.Name;
				vrLine2.text = BuildStatusLine(currentRoom, maxPlayers);
			}
			else
			{
				vrLine1.text = "Not in lobby";
				vrLine2.text = "";
			}
		}
	}

	private string BuildStatusLine(Room room, int maxPlayers)
	{
		string value = (room.IsVisible ? "Public" : "Private");
		string text = CollectAllRoomText(room).ToLowerInvariant();
		string gameModeFromText = GetGameModeFromText(text);
		bool num = IsModdedFromText(text);
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(value);
		if (!string.IsNullOrEmpty(gameModeFromText))
		{
			stringBuilder.Append(" ");
			stringBuilder.Append(gameModeFromText);
		}
		if (num)
		{
			stringBuilder.Append(" Modded");
		}
		stringBuilder.Append(" | Players: ");
		stringBuilder.Append(room.PlayerCount);
		stringBuilder.Append("/");
		stringBuilder.Append(maxPlayers);
		return stringBuilder.ToString();
	}

	private string CollectAllRoomText(Room room)
	{
		//IL_0087: 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)
		StringBuilder stringBuilder = new StringBuilder();
		if (room == null)
		{
			return "";
		}
		if (!string.IsNullOrEmpty(room.Name))
		{
			stringBuilder.Append(room.Name).Append(" ");
		}
		stringBuilder.Append(room.IsVisible ? "public " : "private ");
		stringBuilder.Append(room.PlayerCount).Append(" ");
		stringBuilder.Append(room.MaxPlayers).Append(" ");
		Hashtable customProperties = ((RoomInfo)room).CustomProperties;
		if (customProperties != null)
		{
			DictionaryEntryEnumerator enumerator = customProperties.GetEnumerator();
			try
			{
				while (((DictionaryEntryEnumerator)(ref enumerator)).MoveNext())
				{
					DictionaryEntry current = ((DictionaryEntryEnumerator)(ref enumerator)).Current;
					if (current.Key != null)
					{
						stringBuilder.Append(current.Key.ToString()).Append(" ");
					}
					if (current.Value != null)
					{
						stringBuilder.Append(current.Value.ToString()).Append(" ");
					}
				}
			}
			finally
			{
				((IDisposable)(DictionaryEntryEnumerator)(ref enumerator)).Dispose();
			}
		}
		return stringBuilder.ToString();
	}

	private string GetGameModeFromText(string text)
	{
		if (string.IsNullOrWhiteSpace(text))
		{
			return "Unknown";
		}
		if (text.Contains("infection"))
		{
			return "Infection";
		}
		if (text.Contains("casual"))
		{
			return "Casual";
		}
		if (text.Contains("hunt"))
		{
			return "Hunt";
		}
		if (text.Contains("paintbrawl") || text.Contains("paint brawl"))
		{
			return "Paintbrawl";
		}
		if (text.Contains("guardian"))
		{
			return "Guardian";
		}
		if (text.Contains("freeze"))
		{
			return "Freeze";
		}
		if (text.Contains("ambush"))
		{
			return "Ambush";
		}
		if (text.Contains("ghost"))
		{
			return "Ghost";
		}
		if (text.Contains("competitive"))
		{
			return "Competitive";
		}
		if (text.Contains("minigame") || text.Contains("mini game"))
		{
			return "Minigames";
		}
		return "Unknown";
	}

	private bool IsModdedFromText(string text)
	{
		if (string.IsNullOrWhiteSpace(text))
		{
			return false;
		}
		if (!text.Contains("modded") && !text.Contains("mod ") && !text.Contains(" mod") && !text.Contains("mods"))
		{
			return text.Contains("mods=");
		}
		return true;
	}

	private Camera GetMainCamera()
	{
		if ((Object)(object)Camera.main != (Object)null)
		{
			return Camera.main;
		}
		Camera[] array = Object.FindObjectsOfType<Camera>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i] != (Object)null && ((Behaviour)array[i]).enabled)
			{
				return array[i];
			}
		}
		return null;
	}
}