Decompiled source of Summit Roster Forked v1.0.0

SummitRosterForked.dll

Decompiled a week 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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 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("SummitRosterForked", "Summit Roster Forked", "1.0.0")]
	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 SummitRosterForked is loaded!");
			SettingsRegistry.Register("Summit Roster");
		}

		private void Start()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			SettingsHandler.Instance.AddSetting((Setting)new DisplayModeSetting());
			SettingsHandler.Instance.AddSetting((Setting)new DisplayRangeSetting());
			SettingsHandler.Instance.AddSetting((Setting)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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass21_0
		{
			public Player newPlayer;

			internal bool <WaitAndAddPlayer>b__0()
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				return (Object)PlayerHandler.GetPlayerCharacter(newPlayer) != (Object)null;
			}
		}

		[CompilerGenerated]
		private sealed class <WaitAndAddPlayer>d__21 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Player newPlayer;

			public SummitRoster <>4__this;

			private <>c__DisplayClass21_0 <>8__1;

			private SummitRoster <map>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitAndAddPlayer>d__21(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>8__1 = null;
				<map>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass21_0();
					<>8__1.newPlayer = newPlayer;
					<>2__current = (object)new WaitUntil((Func<bool>)(() => (Object)PlayerHandler.GetPlayerCharacter(<>8__1.newPlayer) != (Object)null));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<map>5__2 = GameObject.Find("SummitRoster").GetComponent<SummitRoster>();
					<map>5__2.AddCharacter(PlayerHandler.GetPlayerCharacter(<>8__1.newPlayer));
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			if ((Object)overlay != (Object)null)
			{
				Object.DestroyImmediate((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)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_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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)tick);
			}
			ticks.Clear();
			int num = 40;
			Vector2 val = default(Vector2);
			for (int i = 0; i < num; i++)
			{
				GameObject val2 = new GameObject("Tick", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val2.transform.SetParent(overlay.transform);
				Image component = val2.GetComponent<Image>();
				((Graphic)component).color = new Color(0.75f, 0.75f, 0.69f, 0.6f);
				RectTransform component2 = val2.GetComponent<RectTransform>();
				component2.sizeDelta = new Vector2(15f, 3f);
				((Vector2)(ref val))..ctor(0f, 0.5f);
				component2.anchorMax = val;
				component2.anchorMin = val;
				component2.pivot = new Vector2(0.5f, 0.5f);
				ticks.Add(val2);
			}
		}

		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));
		}

		[IteratorStateMachine(typeof(<WaitAndAddPlayer>d__21))]
		private IEnumerator WaitAndAddPlayer(Player newPlayer)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitAndAddPlayer>d__21(0)
			{
				<>4__this = this,
				newPlayer = 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_0071: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: 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)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			GameObject val = characterLabels[character];
			Object.DestroyImmediate((Object)val);
			characterLabels.Remove(character);
		}
	}
}