Decompiled source of PeakSummit v0.1.0

plugins/dev.kesor.PeakSummit.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("dev.kesor.peaksummit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("dev.kesor.peaksummit")]
[assembly: AssemblyTitle("PeakSummit")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PeakSummit
{
	[BepInPlugin("dev.kesor.peaksummit", "PeakSummit", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private readonly Harmony _harmony = new Harmony("dev.kesor.peaksummit");

		public static ConfigEntry<float> ConfigX;

		public static ConfigEntry<float> ConfigY;

		public static ConfigEntry<float> ConfigSize;

		public static ConfigEntry<string> ConfigColor;

		private Rect _windowRect = new Rect(20f, 20f, 340f, 200f);

		private string _inputSize = "";

		private string _inputColor = "";

		private float _nextUiRefresh;

		private bool _isDraggingElement;

		public static bool IsEditMode { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigX = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "X Position", 0f, "Horizontal shift from center.");
			ConfigY = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "Y Position", -50f, "Vertical shift from top edge.");
			ConfigSize = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "Font Size", 36f, "Size of the text.");
			ConfigColor = ((BaseUnityPlugin)this).Config.Bind<string>("Visual", "Hex Color", "#FFFFFF", "Color of the text in HEX.");
			SyncInputs();
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)"PeakSummit loaded successfully!");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}

		private void Update()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			if (!GUIManager.InPauseMenu)
			{
				if (IsEditMode)
				{
					IsEditMode = false;
					_isDraggingElement = false;
				}
				if (Time.time >= _nextUiRefresh)
				{
					_nextUiRefresh = Time.time + 1f;
					SyncInputs();
				}
			}
			else if (IsEditMode && (Object)(object)UIPatch.TextPos != (Object)null)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				Vector2 val = Vector2.op_Implicit(Input.mousePosition);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor((float)Screen.width * 0.5f, (float)Screen.height);
				Vector2 val3 = val2 + new Vector2(ConfigX.Value, ConfigY.Value);
				float num = ConfigSize.Value * 2f;
				if (Input.GetMouseButtonDown(0) && Vector2.Distance(val, val3) <= num)
				{
					_isDraggingElement = true;
				}
				if (Input.GetMouseButton(0) && _isDraggingElement)
				{
					Vector2 val4 = val - val2;
					ConfigX.Value = Mathf.Clamp(val4.x, (float)(-Screen.width) * 0.5f, (float)Screen.width * 0.5f);
					ConfigY.Value = Mathf.Clamp(val4.y, (float)(-Screen.height), 0f);
				}
				if (Input.GetMouseButtonUp(0))
				{
					_isDraggingElement = false;
					((BaseUnityPlugin)this).Config.Save();
				}
			}
		}

		private void OnGUI()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (GUIManager.InPauseMenu)
			{
				if (IsEditMode)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
					GUI.Box(new Rect((float)Screen.width * 0.5f - 175f, 10f, 350f, 25f), "DRAG TEXT WITH LKM | Close Pause Menu to Exit");
				}
				else
				{
					_windowRect = GUI.Window(937452, _windowRect, new WindowFunction(DrawWindow), "PeakSummit Settings");
				}
			}
		}

		private void DrawWindow(int id)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			if (GUI.Button(new Rect(15f, 25f, 310f, 35f), "DRAG INTERFACE WITH MOUSE"))
			{
				IsEditMode = true;
			}
			GUI.Label(new Rect(15f, 75f, 130f, 20f), "Font Size:");
			_inputSize = GUI.TextField(new Rect(150f, 75f, 175f, 22f), _inputSize, 8);
			GUI.Label(new Rect(15f, 105f, 130f, 20f), "Hex Color:");
			_inputColor = GUI.TextField(new Rect(150f, 105f, 175f, 22f), _inputColor, 9);
			if (GUI.Button(new Rect(15f, 140f, 150f, 30f), "Save Changes"))
			{
				ApplySettings();
			}
			if (GUI.Button(new Rect(175f, 140f, 150f, 30f), "Reset to Default"))
			{
				ConfigX.Value = 0f;
				ConfigY.Value = -50f;
				_inputSize = "36";
				_inputColor = "#FFFFFF";
				ApplySettings();
			}
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
		}

		private void SyncInputs()
		{
			_inputSize = ConfigSize.Value.ToString("0.##");
			_inputColor = ConfigColor.Value;
		}

		private void ApplySettings()
		{
			if (float.TryParse(_inputSize, NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || float.TryParse(_inputSize, out result))
			{
				ConfigSize.Value = Mathf.Clamp(result, 10f, 150f);
			}
			string text = _inputColor.Trim();
			if (!text.StartsWith("#"))
			{
				text = "#" + text;
			}
			Color val = default(Color);
			if ((text.Length == 4 || text.Length == 7 || text.Length == 9) && ColorUtility.TryParseHtmlString(text, ref val))
			{
				ConfigColor.Value = text;
				_inputColor = text;
			}
			((BaseUnityPlugin)this).Config.Save();
		}
	}
	[HarmonyPatch]
	internal class UIPatch
	{
		public static GameObject AltitudeText;

		public static TextMeshProUGUI TextComponent;

		public static RectTransform TextPos;

		[HarmonyPatch(typeof(GUIManager), "Start")]
		[HarmonyPostfix]
		private static void InsertUI(GUIManager __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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)
			AltitudeText = new GameObject("PeakSummitText");
			TextComponent = AltitudeText.AddComponent<TextMeshProUGUI>();
			((TMP_Text)TextComponent).font = ((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "DarumaDropOne-Regular SDF"));
			((TMP_Text)TextComponent).fontSize = Plugin.ConfigSize.Value;
			((TMP_Text)TextComponent).alignment = (TextAlignmentOptions)514;
			Color color = default(Color);
			if (ColorUtility.TryParseHtmlString(Plugin.ConfigColor.Value, ref color))
			{
				((Graphic)TextComponent).color = color;
			}
			AltitudeText.transform.SetParent(((Component)__instance.hudCanvas).transform, false);
			TextPos = AltitudeText.GetComponent<RectTransform>();
			TextPos.anchorMin = new Vector2(0.5f, 1f);
			TextPos.anchorMax = new Vector2(0.5f, 1f);
			TextPos.pivot = new Vector2(0.5f, 1f);
			TextPos.anchoredPosition = new Vector2(Plugin.ConfigX.Value, Plugin.ConfigY.Value);
		}

		[HarmonyPatch(typeof(CharacterStats), "Update")]
		[HarmonyPostfix]
		private static void GetHeight(CharacterStats __instance)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)TextComponent == (Object)null || (Object)(object)__instance.character == (Object)null || (Object)(object)__instance.character.data == (Object)null || __instance.character.data.dead)
			{
				return;
			}
			float heightInMeters = __instance.heightInMeters;
			((TMP_Text)TextComponent).SetText($"{heightInMeters:N0}m");
			if ((Object)(object)TextPos != (Object)null && (Time.frameCount % 2 == 0 || Plugin.IsEditMode || GUIManager.InPauseMenu))
			{
				TextPos.anchoredPosition = new Vector2(Plugin.ConfigX.Value, Plugin.ConfigY.Value);
				((TMP_Text)TextComponent).fontSize = Plugin.ConfigSize.Value;
				Color color = default(Color);
				if (ColorUtility.TryParseHtmlString(Plugin.ConfigColor.Value, ref color))
				{
					((Graphic)TextComponent).color = color;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}