Decompiled source of AdminMenuButtonPositionFix v1.3.0

AdminMenuButtonPositionFix.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using MenuLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 AdminMenuButtonPositionFix
{
	[BepInPlugin("ricketywrecked.repo.adminmenubuttonfix", "Admin Menu Button Position Fix", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "ricketywrecked.repo.adminmenubuttonfix";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("ricketywrecked.repo.adminmenubuttonfix").PatchAll(Assembly.GetExecutingAssembly());
			Log.LogInfo((object)"Admin Menu Button Position Fix loaded.");
		}
	}
	[HarmonyPatch(typeof(MenuAPI), "CreateREPOButton", new Type[]
	{
		typeof(string),
		typeof(Action),
		typeof(Transform),
		typeof(Vector2)
	})]
	internal static class AdminMenuButtonRepositionPatch
	{
		private const float ModsButtonY = 65f;

		private const float FallbackY = 94f;

		private static void Prefix(string text, Transform parent, ref Vector2 localPosition)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!(text != "Admin Menu"))
			{
				float num = 94f;
				float? num2 = FindSiblingY(parent, "Menu Button - Main Menu");
				if (num2.HasValue)
				{
					num = (65f + num2.Value) / 2f;
				}
				else
				{
					Plugin.Log.LogWarning((object)"Couldn't find Main Menu button to measure against; using fallback position.");
				}
				localPosition = new Vector2(126f, num);
			}
		}

		private static float? FindSiblingY(Transform parent, string childName)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)parent == (Object)null)
			{
				return null;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (((Object)child).name == childName)
				{
					return child.localPosition.y;
				}
			}
			return null;
		}
	}
}