Decompiled source of HideNSeek CORE v2.0.0

BepInEx/plugins/mrov-MainMenuVersion/MainMenuVersion.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Diagnostics;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("MainMenuVersion")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("MainMenuVersion")]
[assembly: AssemblyTitle("MainMenuVersion")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 MainMenuVersion
{
	public class ConfigManager
	{
		private readonly ConfigFile configFile;

		public static ConfigManager Instance { get; private set; }

		public static ConfigEntry<string> VersionEntry { get; private set; }

		public static ConfigEntry<float> Size { get; private set; }

		public static ConfigEntry<float> YOffset { get; private set; }

		public static ConfigEntry<bool> AlwaysShortVersion { get; private set; }

		public static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}

		private ConfigManager(ConfigFile config)
		{
			configFile = config;
			VersionEntry = configFile.Bind<string>("General", "Version", "v%VERSION% [MODDED]", "The version string to display on the main menu");
			Size = configFile.Bind<float>("General", "Size", 20f, "The size of the version string");
			YOffset = configFile.Bind<float>("General", "YOffset", 0f, "The Y offset of the version string");
			AlwaysShortVersion = configFile.Bind<bool>("General", "AlwaysShortVersion", true, "Always display the short version of the game - this ignores LC_API and MoreCompany changes");
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	public class MenuManagerPatch
	{
		private static MenuManager Instance;

		internal static GameObject VersionNum = null;

		internal static Transform MenuContainer = null;

		internal static Transform MenuPanel = null;

		public static Color32 DARK_ORANGE = new Color32((byte)175, (byte)115, (byte)0, byte.MaxValue);

		public static TextMeshProUGUI versionText { get; private set; }

		public static RectTransform versionTextRect { get; private set; }

		public static int realVer { get; internal set; }

		public static int gameVer { get; private set; }

		[HarmonyPatch(typeof(GameNetworkManager))]
		[HarmonyPrefix]
		[HarmonyPatch("Awake")]
		private static void SetRealVersion(GameNetworkManager __instance)
		{
			realVer = __instance.gameVersionNum;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Init(MenuManager __instance)
		{
			Instance = __instance;
			((MonoBehaviour)Instance).StartCoroutine(PatchMenuDelayed());
		}

		private static IEnumerator PatchMenuDelayed()
		{
			yield return (object)new WaitUntil((Func<bool>)(() => !GameNetworkManager.Instance.firstTimeInMenu));
			GameObject obj = GameObject.Find("MenuContainer");
			MenuContainer = ((obj != null) ? obj.transform : null);
			Transform menuContainer = MenuContainer;
			MenuPanel = ((menuContainer != null) ? menuContainer.Find("MainButtons") : null);
			Transform menuContainer2 = MenuContainer;
			object versionNum;
			if (menuContainer2 == null)
			{
				versionNum = null;
			}
			else
			{
				Transform obj2 = menuContainer2.Find("VersionNum");
				versionNum = ((obj2 != null) ? ((Component)obj2).gameObject : null);
			}
			VersionNum = (GameObject)versionNum;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		[HarmonyPriority(0)]
		private static void UpdatePatch(MenuManager __instance)
		{
			bool activeSelf = __instance.menuButtons.activeSelf;
			RectTransform[] array = Object.FindObjectsOfType<RectTransform>();
			RectTransform[] array2 = array;
			foreach (RectTransform val in array2)
			{
				if (((Object)val).name == "VersionNumberText")
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
			if ((Object)(object)versionText == (Object)null)
			{
				TryReplaceVersionText();
				return;
			}
			((TMP_Text)versionText).text = ConfigManager.VersionEntry.Value.Replace("%VERSION%", $"{gameVer}");
			GameObject gameObject = ((Component)versionText).gameObject;
			if (!gameObject.activeSelf && activeSelf)
			{
				gameObject.SetActive(true);
			}
		}

		internal static void TryReplaceVersionText()
		{
			if (!((Object)(object)VersionNum == (Object)null) && !((Object)(object)MenuPanel == (Object)null))
			{
				GameObject val = Object.Instantiate<GameObject>(VersionNum, MenuPanel);
				((Object)val).name = "MainMenuVersion";
				versionText = InitTextMesh(val.GetComponent<TextMeshProUGUI>());
				versionTextRect = ((Component)versionText).gameObject.GetComponent<RectTransform>();
				versionTextRect.AnchorToBottom();
				VersionNum.SetActive(false);
			}
		}

		private static void SetVersion()
		{
			bool value = ConfigManager.AlwaysShortVersion.Value;
			int num = Math.Abs(GameNetworkManager.Instance.gameVersionNum);
			gameVer = (value ? realVer : ((num != realVer) ? num : realVer));
		}

		private static TextMeshProUGUI InitTextMesh(TextMeshProUGUI tmp)
		{
			SetVersion();
			((TMP_Text)tmp).text = ConfigManager.VersionEntry.Value;
			((TMP_Text)tmp).fontSize = ConfigManager.Size.ClampedValue(10f, 40f);
			((TMP_Text)tmp).alignment = (TextAlignmentOptions)514;
			TweakTextSettings(tmp);
			return tmp;
		}

		private static void TweakTextSettings(TextMeshProUGUI tmp, bool overflow = true, bool wordWrap = false)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (overflow)
			{
				((TMP_Text)tmp).overflowMode = (TextOverflowModes)0;
			}
			((TMP_Text)tmp).enableWordWrapping = wordWrap;
			((TMP_Text)tmp).faceColor = DARK_ORANGE;
		}
	}
	[BepInPlugin("MainMenuVersion", "MainMenuVersion", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		internal static Harmony harmony = new Harmony("MainMenuVersion");

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MainMenuVersion is loaded!");
		}
	}
	internal static class Extensions
	{
		internal static GameObject FindInParent(this GameObject obj, string name)
		{
			Transform parent = obj.transform.parent;
			try
			{
				return ((Component)parent.Find(name)).gameObject;
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Error finding '{name}' in: {((Object)parent).name}\n{arg}");
				return null;
			}
		}

		internal static bool IsAbove(this Transform cur, Transform target)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return cur.localPosition.y > target.localPosition.y;
		}

		internal static void ResetAnchoredPos(this RectTransform rect)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			rect.anchoredPosition = Vector2.zero;
			rect.anchoredPosition3D = Vector3.zero;
		}

		internal static void ResetPivot(this RectTransform rect)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rect.pivot = Vector2.zero;
		}

		internal static void ResetSizeDelta(this RectTransform rect)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			rect.sizeDelta = Vector2.zero;
		}

		internal static void EditOffsets(this RectTransform rect, Vector2 max, Vector2 min)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			rect.offsetMax = max;
			rect.offsetMin = min;
		}

		internal static void EditAnchors(this RectTransform rect, Vector2 max, Vector2 min)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMax = max;
			rect.anchorMin = min;
		}

		internal static void AnchorToBottomRight(this RectTransform rect)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			rect.ResetAnchoredPos();
			rect.EditAnchors(new Vector2(1f, 0f), new Vector2(1f, 0f));
			((Transform)rect).localPosition = new Vector3(432f, -222f, 0f);
			((Transform)rect).localRotation = Quaternion.identity;
		}

		internal static void AnchorToBottom(this RectTransform rect)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			rect.ResetSizeDelta();
			rect.ResetAnchoredPos();
			rect.EditAnchors(new Vector2(0.5f, 0f), new Vector2(0.5f, 0f));
			rect.EditOffsets(new Vector2(0f, 0f), new Vector2(0f, 0f));
			rect.RefreshPosition();
		}

		internal static void RefreshPosition(this RectTransform rect)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			float value = ConfigManager.YOffset.Value;
			((Transform)rect).localPosition = new Vector3(0f, -205f + value, 0f);
			((Transform)rect).localRotation = Quaternion.identity;
		}

		internal static void SetLocalX(this RectTransform rect, float newX)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			((Transform)rect).localPosition = new Vector3(newX, ((Transform)rect).localPosition.y, ((Transform)rect).localPosition.z);
		}

		internal static void FixScale(this Transform transform)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			transform.localScale = new Vector3(1.02f, 1.06f, 1.02f);
		}

		internal static float ClampedValue(this ConfigEntry<float> entry, float min, float max)
		{
			return Mathf.Clamp(entry.Value, min, max);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MainMenuVersion";

		public const string PLUGIN_NAME = "MainMenuVersion";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}