Decompiled source of UIScale v0.1.0

UIScale.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using RoR2.UI;
using RoR2.UI.LogBook;
using RoR2.UI.MainMenu;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace Prototype;

[BepInPlugin("ui.scale", "UIScale", "0.1.0")]
public class UIScale : BaseUnityPlugin
{
	public const string version = "0.1.0";

	public const string identifier = "ui.scale";

	private static float percentage;

	private static Transform instance;

	public void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		percentage = ((BaseUnityPlugin)this).Config.Bind<float>("Width", "Percentage", 75f, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<float>(50f, 100f), Array.Empty<object>())).Value / 100f;
		Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
	}

	private static void Resize(Transform transform)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		float pivot;
		if (Object.op_Implicit((Object)(object)val))
		{
			pivot = val.pivot.x;
			if (pivot <= 0f || pivot >= 1f)
			{
				pivot = 0.5f;
			}
			val.anchorMin = resize(val.anchorMin);
			val.anchorMax = resize(val.anchorMax);
		}
		Vector2 resize(Vector2 anchor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(pivot + percentage * (anchor.x - pivot), anchor.y);
		}
	}

	private static void Resize(Component parent, string path)
	{
		Resize(parent.transform.Find(path));
	}

	[HarmonyPatch(typeof(MainMenuController), "Awake")]
	[HarmonyPostfix]
	private static void Hook(MainMenuController __instance)
	{
		Resize((Component)(object)__instance, "MENU: Title/TitleMenu/SafeZone");
		Resize((Component)(object)__instance, "MENU: Multiplayer/MultiplayerMenu2/Inner90");
		Resize((Component)(object)__instance, "MENU: Extra Game Mode/ExtraGameModeMenu/Main Panel");
		Resize((Component)(object)__instance, "MENU: More/MoreMenu/Main Panel");
	}

	[HarmonyPatch(typeof(EclipseRunScreenController), "Awake")]
	[HarmonyPatch(typeof(InfiniteTowerMenuController), "Awake")]
	[HarmonyPatch(typeof(WeeklyRunScreenController), "OnEnable")]
	[HarmonyPostfix]
	private static void Hook(Component __instance)
	{
		Resize(__instance, "Main Panel");
	}

	[HarmonyPatch(typeof(CharacterSelectController), "Awake")]
	[HarmonyPostfix]
	private static void Hook(CharacterSelectController __instance)
	{
		Resize((Component)(object)__instance, "SafeArea");
	}

	[HarmonyPatch(typeof(SettingsPanelController), "Start")]
	[HarmonyPostfix]
	private static void Hook(SettingsPanelController __instance)
	{
		Resize(Object.op_Implicit((Object)(object)instance) ? null : (instance = ((Component)__instance).transform.parent.parent));
	}

	[HarmonyPatch(typeof(HUD), "Awake")]
	[HarmonyPostfix]
	private static void Hook(HUD __instance)
	{
		Resize((Component)(object)__instance, "MainContainer/MainUIArea/SpringCanvas");
	}

	[HarmonyPatch(typeof(GameEndReportPanelController), "Awake")]
	[HarmonyPostfix]
	private static void Hook(GameEndReportPanelController __instance)
	{
		Resize((Component)(object)__instance, "SafeArea (JUICED)");
	}

	[HarmonyPatch(typeof(LogBookController), "Awake")]
	[HarmonyPostfix]
	private static void Hook(LogBookController __instance)
	{
		Resize((Component)(object)__instance, "LogbookPanel");
	}
}