Decompiled source of Summit Roster v1.1.2

plugins/SummitRoster.dll

Decompiled a month ago
using System;
using System.Collections;
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.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using SettingsExtender;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore;
using UnityEngine.UI;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SummitRoster")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+736bc10c1e01ba2800d38a89f21eabcd7ab5d16a")]
[assembly: AssemblyProduct("Summit Roster")]
[assembly: AssemblyTitle("SummitRoster")]
[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 SummitRoster
{
	internal class DisplayModeSetting : EnumSetting<DisplayModeSetting.DisplayMode>, IExposedSetting
	{
		public enum DisplayMode
		{
			Full,
			Centered
		}

		public string GetDisplayName()
		{
			return "Display mode";
		}

		public string GetCategory()
		{
			return SettingsRegistry.GetPageId("Summit Roster");
		}

		protected override DisplayMode GetDefaultValue()
		{
			return DisplayMode.Full;
		}

		public override List<LocalizedString> GetLocalizedChoices()
		{
			return null;
		}

		public override void ApplyValue()
		{
		}
	}
	public class DisplayRangeSetting : FloatSetting, IExposedSetting
	{
		public string GetDisplayName()
		{
			return "Centered: Visibility range (m)";
		}

		public string GetCategory()
		{
			return SettingsRegistry.GetPageId("Summit Roster");
		}

		protected override float GetDefaultValue()
		{
			return 50f;
		}

		protected override float2 GetMinMaxValue()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new float2(10f, 500f);
		}

		public override void ApplyValue()
		{
		}
	}
	public class DisplayScaleSetting : FloatSetting, IExposedSetting
	{
		public string GetDisplayName()
		{
			return "Centered: Zoom factor";
		}

		public string GetCategory()
		{
			return SettingsRegistry.GetPageId("Summit Roster");
		}

		protected override float GetDefaultValue()
		{
			return 1f;
		}

		protected override float2 GetMinMaxValue()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new float2(0.1f, 20f);
		}

		public override void ApplyValue()
		{
		}
	}
	[BepInPlugin("SummitRoster", "Summit Roster", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static readonly string[] SkipScenes = new string[2] { "Pretitle", "Title" };

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin SummitRoster is loaded!");
			SettingsRegistry.Register("Summit Roster");
		}

		private void Start()
		{
			SettingsHandler.Instance.AddSetting((Setting)(object)new DisplayModeSetting());
			SettingsHandler.Instance.AddSetting((Setting)(object)new DisplayRangeSetting());
			SettingsHandler.Instance.AddSetting((Setting)(object)new DisplayScaleSetting());
		}

		private void OnEnable()
		{
			Logger.LogInfo((object)"Plugin enabled");
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			Logger.LogInfo((object)"Plugin disabled");
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			Logger.LogInfo((object)(((Scene)(ref scene)).name + " loaded"));
			if (!SkipScenes.Contains(((Scene)(ref scene)).name))
			{
				GameObject val = new GameObject("SummitRoster", new Type[1] { typeof(SummitRoster) });
			}
		}
	}
	public class SummitRoster : MonoBehaviourPunCallbacks
	{
		public static SummitRoster Instance;

		private GameObject overlay;

		private GameObject peakGO;

		private TMP_FontAsset mainFont;

		private readonly Dictionary<Character, GameObject> characterLabels = new Dictionary<Character, GameObject>();

		private const float totalMountainHeight = 1920f;

		private const float barHeightPixels = 800f;

		private const float leftOffset = 60f;

		private const float bottomOffset = 50f;

		private DisplayModeSetting.DisplayMode displayMode = DisplayModeSetting.DisplayMode.Full;

		private float displayRange = 100f;

		private float displayScale = 10f;

		private readonly List<GameObject> ticks = new List<GameObject>();

		private void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			if ((Object)(object)overlay != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)overlay);
			}
			overlay = new GameObject("ProgressMap");
			Canvas val = overlay.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			CanvasScaler val2 = overlay.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			if ((Object)(object)mainFont == (Object)null)
			{
				TMP_FontAsset[] source = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				mainFont = ((IEnumerable<TMP_FontAsset>)source).FirstOrDefault((Func<TMP_FontAsset, bool>)delegate(TMP_FontAsset a)
				{
					//IL_0001: 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)
					FaceInfo faceInfo = ((TMP_Asset)a).faceInfo;
					return ((FaceInfo)(ref faceInfo)).familyName == "Daruma Drop One";
				});
			}
			peakGO = new GameObject("PeakText", new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
			peakGO.transform.SetParent(overlay.transform, false);
			TextMeshProUGUI component = peakGO.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).font = mainFont;
			((TMP_Text)component).text = "PEAK";
			((Graphic)component).color = new Color(1f, 1f, 1f, 0.3f);
			RectTransform component2 = peakGO.GetComponent<RectTransform>();
			component2.sizeDelta = ((TMP_Text)component).GetPreferredValues();
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 0.5f);
			component2.anchorMax = val3;
			component2.anchorMin = val3;
			component2.pivot = new Vector2(0.5f, 0f);
			component2.anchoredPosition = new Vector2(60f, 450f);
			GameObject val4 = new GameObject("AltitudeBar");
			val4.transform.SetParent(overlay.transform, false);
			RectTransform val5 = val4.AddComponent<RectTransform>();
			((Vector2)(ref val3))..ctor(0f, 0.5f);
			val5.anchorMax = val3;
			val5.anchorMin = val3;
			val5.sizeDelta = new Vector2(10f, 800f);
			val5.anchoredPosition = new Vector2(60f, 50f);
			Image val6 = val4.AddComponent<Image>();
			((Graphic)val6).color = new Color(0.75f, 0.75f, 0.69f, 0.3f);
		}

		private void Start()
		{
			displayMode = ((EnumSetting<DisplayModeSetting.DisplayMode>)SettingsHandler.Instance.GetSetting<DisplayModeSetting>()).Value;
			displayRange = ((FloatSetting)SettingsHandler.Instance.GetSetting<DisplayRangeSetting>()).Value;
			displayScale = ((FloatSetting)SettingsHandler.Instance.GetSetting<DisplayRangeSetting>()).Value;
			CreateTicks();
			characterLabels.Clear();
			foreach (Character allCharacter in Character.AllCharacters)
			{
				AddCharacter(allCharacter);
			}
		}

		private void DrawMarkers()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Character allCharacter in Character.AllCharacters)
			{
				DrawCharacter(allCharacter);
			}
			int num = -20;
			foreach (GameObject tick in ticks)
			{
				float num2 = 0f;
				if (displayMode == DisplayModeSetting.DisplayMode.Full)
				{
					if (!tick.activeSelf)
					{
					}
				}
				else
				{
					float num3 = Character.localCharacter.Center.y * 1.6f;
					float num4 = Mathf.Ceil(num3 / 10f) * 10f + (float)(num * 10);
					float num5 = num4 - num3;
					float num6 = 400f;
					float num7 = displayScale;
					float num8 = displayRange;
					float num9 = Mathf.Sign(num5);
					float num10 = Mathf.Abs(num5);
					num10 = Mathf.Min(num10, num8);
					float num11 = Mathf.Log(1f + num10 / num7);
					float num12 = Mathf.Log(1f + num8 / num7);
					float num13 = num9 * (num11 / num12);
					Image component = tick.GetComponent<Image>();
					Color color = ((Graphic)component).color;
					color.a = Mathf.Lerp(0.6f, 0f, num11 / num12);
					((Graphic)component).color = color;
					num2 = num13 * num6;
				}
				num++;
				RectTransform component2 = tick.GetComponent<RectTransform>();
				component2.anchoredPosition = new Vector2(60f, 50f + num2);
			}
		}

		public void Refresh()
		{
			CreateTicks();
		}

		private void CreateTicks()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"Creating ticks");
			foreach (GameObject tick in ticks)
			{
				Object.Destroy((Object)(object)tick);
			}
			ticks.Clear();
			int num = 40;
			Vector2 val2 = default(Vector2);
			for (int i = 0; i < num; i++)
			{
				GameObject val = new GameObject("Tick", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val.transform.SetParent(overlay.transform);
				Image component = val.GetComponent<Image>();
				((Graphic)component).color = new Color(0.75f, 0.75f, 0.69f, 0.6f);
				RectTransform component2 = val.GetComponent<RectTransform>();
				component2.sizeDelta = new Vector2(15f, 3f);
				((Vector2)(ref val2))..ctor(0f, 0.5f);
				component2.anchorMax = val2;
				component2.anchorMin = val2;
				component2.pivot = new Vector2(0.5f, 0.5f);
				ticks.Add(val);
			}
		}

		private void DrawCharacter(Character character)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			if (!characterLabels.ContainsKey(character))
			{
				AddCharacter(character);
			}
			GameObject val = characterLabels[character];
			float num = character.Center.y * 1.6f;
			string nickName = character.refs.view.Owner.NickName;
			TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)componentInChildren).text = $"{nickName} {num:0}m";
			((Component)componentInChildren).gameObject.GetComponent<RectTransform>().sizeDelta = ((TMP_Text)componentInChildren).GetPreferredValues() * 1.1f;
			((Graphic)componentInChildren).color = character.refs.customization.PlayerColor;
			((Graphic)val.GetComponentInChildren<Image>()).color = character.refs.customization.PlayerColor;
			float num2 = 0f;
			if (displayMode == DisplayModeSetting.DisplayMode.Full)
			{
				float num3 = Mathf.InverseLerp(0f, 1920f, num);
				num2 = Mathf.Lerp(-400f, 400f, num3);
			}
			else
			{
				float num4 = Character.localCharacter.Center.y * 1.6f;
				float num5 = num - num4;
				float num6 = 400f;
				float num7 = displayScale;
				float num8 = displayRange;
				float num9 = Mathf.Sign(num5);
				float num10 = Mathf.Abs(num5);
				num10 = Mathf.Min(num10, num8);
				float num11 = Mathf.Log(1f + num10 / num7);
				float num12 = Mathf.Log(1f + num8 / num7);
				float num13 = num9 * (num11 / num12);
				num2 = num13 * num6;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchoredPosition = new Vector2(110f, 50f + num2);
		}

		private void LateUpdate()
		{
			displayMode = ((EnumSetting<DisplayModeSetting.DisplayMode>)SettingsHandler.Instance.GetSetting<DisplayModeSetting>()).Value;
			displayRange = ((FloatSetting)SettingsHandler.Instance.GetSetting<DisplayRangeSetting>()).Value;
			displayScale = ((FloatSetting)SettingsHandler.Instance.GetSetting<DisplayScaleSetting>()).Value;
			peakGO.SetActive(displayMode == DisplayModeSetting.DisplayMode.Full);
			DrawMarkers();
		}

		public override void OnPlayerEnteredRoom(Player newPlayer)
		{
			Debug.Log((object)"Adding player to map");
			((MonoBehaviour)this).StartCoroutine(WaitAndAddPlayer(newPlayer));
		}

		private IEnumerator WaitAndAddPlayer(Player newPlayer)
		{
			yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)PlayerHandler.GetPlayerCharacter(newPlayer) != (Object)null));
			SummitRoster map = GameObject.Find("SummitRoster").GetComponent<SummitRoster>();
			map.AddCharacter(PlayerHandler.GetPlayerCharacter(newPlayer));
		}

		public override void OnPlayerLeftRoom(Player leavingPlayer)
		{
			Debug.Log((object)"Removing player from map");
			SummitRoster component = GameObject.Find("SummitRoster").GetComponent<SummitRoster>();
			component.RemoveCharacter(PlayerHandler.GetPlayerCharacter(leavingPlayer));
		}

		public void AddCharacter(Character character)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_009e: Expected O, but got Unknown
			//IL_00c8: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)$"Adding character {character}");
			if (!characterLabels.ContainsKey(character))
			{
				string nickName = character.refs.view.Owner.NickName;
				GameObject val = new GameObject("Label_" + nickName);
				val.transform.SetParent(overlay.transform, false);
				RectTransform val2 = val.AddComponent<RectTransform>();
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(0f, 0.5f);
				val2.anchorMax = val3;
				val2.anchorMin = val3;
				GameObject val4 = new GameObject("Marker");
				val4.transform.SetParent(val.transform, false);
				Image val5 = val4.AddComponent<Image>();
				((Graphic)val5).color = character.refs.customization.PlayerColor;
				RectTransform component = val4.GetComponent<RectTransform>();
				((Vector2)(ref val3))..ctor(0f, 0.5f);
				component.anchorMax = val3;
				component.anchorMin = val3;
				component.pivot = new Vector2(0.5f, 1f);
				component.sizeDelta = new Vector2(10f, 5f);
				GameObject val6 = new GameObject("Text");
				val6.transform.SetParent(val.transform, false);
				TextMeshProUGUI val7 = val6.AddComponent<TextMeshProUGUI>();
				((Graphic)val7).color = character.refs.customization.PlayerColor;
				((TMP_Text)val7).font = mainFont;
				((TMP_Text)val7).fontSize = 18f;
				RectTransform component2 = val6.GetComponent<RectTransform>();
				((Vector2)(ref val3))..ctor(0f, 0.5f);
				component2.anchorMax = val3;
				component2.anchorMin = val3;
				component2.pivot = new Vector2(0f, 0.5f);
				component2.anchoredPosition = new Vector2(20f, 0f);
				characterLabels[character] = val;
			}
		}

		public void RemoveCharacter(Character character)
		{
			GameObject val = characterLabels[character];
			Object.DestroyImmediate((Object)(object)val);
			characterLabels.Remove(character);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SummitRoster";

		public const string PLUGIN_NAME = "Summit Roster";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}