Decompiled source of LCUltrawide v1.1.1

BepInEx/plugins/LCUltrawide.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("stefan750")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod that allows changing of the resolution and aspect ratio of the game and UI elements")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+516a65c96fe17ba1154e9435a986f5bce37b2daf")]
[assembly: AssemblyProduct("LCUltrawide")]
[assembly: AssemblyTitle("LCUltrawide")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 LCUltrawide
{
	[BepInPlugin("LCUltrawide", "LCUltrawide", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		private static ConfigEntry<int> configResW;

		private static ConfigEntry<int> configResH;

		private static ConfigEntry<float> configUIScale;

		private static ConfigEntry<float> configUIAspect;

		private static float aspectUpdateTime = 1f;

		private static bool aspectAutoDetect = false;

		private static float prevAspect = 0f;

		private static float prevTime = 0f;

		private static float fDefaultHelmetWidth = 0.3628f;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LCUltrawide is loaded!");
			configResW = ((BaseUnityPlugin)this).Config.Bind<int>("Resolution Override", "Width", 0, "Horizontal rendering resolution override.\nIf set to 0, the resolution will be automatically adjusted to fit your monitors aspect ratio.\nGame default value: 860");
			configResH = ((BaseUnityPlugin)this).Config.Bind<int>("Resolution Override", "Height", 0, "Vertical rendering resolution override.\nIf set to 0, the original resolution will be used.\nGame default value: 520");
			configUIScale = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "Scale", 1f, "Changes the size of UI elements on the screen.");
			configUIAspect = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "AspectRatio", 0f, "Changes the aspect ratio of the ingame HUD, a higher number makes the HUD wider.\n(0 = auto, 1.33 = 4:3, 1.77 = 16:9, 2.33 = 21:9, 3.55 = 32:9)");
			aspectAutoDetect = configResW.Value <= 0;
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public static void ChangeAspectRatio(float newAspect)
		{
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			HUDManager instance = HUDManager.Instance;
			Texture texture = instance.playerScreenTexture.texture;
			RenderTexture val = (RenderTexture)(object)((texture is RenderTexture) ? texture : null);
			val.Release();
			((Texture)val).height = ((configResH.Value > 0) ? configResH.Value : ((Texture)val).height);
			((Texture)val).width = ((configResW.Value > 0) ? configResW.Value : Convert.ToInt32((float)((Texture)val).height * newAspect));
			GameObject val2 = GameObject.Find("TerminalScript");
			Terminal val3 = default(Terminal);
			if ((Object)(object)val2 != (Object)null && val2.TryGetComponent<Terminal>(ref val3))
			{
				RenderTexture playerScreenTexHighRes = val3.playerScreenTexHighRes;
				playerScreenTexHighRes.Release();
				((Texture)playerScreenTexHighRes).height = ((configResH.Value > 0) ? configResH.Value : ((Texture)playerScreenTexHighRes).height);
				((Texture)playerScreenTexHighRes).width = ((configResW.Value > 0) ? configResW.Value : Convert.ToInt32((float)((Texture)playerScreenTexHighRes).height * newAspect));
			}
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
			{
				GameNetworkManager.Instance.localPlayerController.gameplayCamera.ResetAspect();
			}
			GameObject val4 = GameObject.Find("Systems/UI/Canvas/Panel");
			AspectRatioFitter val5 = default(AspectRatioFitter);
			if ((Object)(object)val4 != (Object)null && val4.TryGetComponent<AspectRatioFitter>(ref val5))
			{
				val5.aspectRatio = newAspect;
			}
			GameObject val6 = GameObject.Find("Systems/UI/Canvas");
			CanvasScaler val7 = default(CanvasScaler);
			if ((Object)(object)val6 != (Object)null && val6.TryGetComponent<CanvasScaler>(ref val7))
			{
				float num = 500f / configUIScale.Value;
				float num2 = num * newAspect;
				val7.referenceResolution = new Vector2(num2, num);
			}
			GameObject hUDContainer = instance.HUDContainer;
			AspectRatioFitter val8 = default(AspectRatioFitter);
			if ((Object)(object)hUDContainer != (Object)null && hUDContainer.TryGetComponent<AspectRatioFitter>(ref val8))
			{
				val8.aspectRatio = ((configUIAspect.Value > 0f) ? configUIAspect.Value : newAspect);
			}
			GameObject val9 = GameObject.Find("Systems/UI/UICamera");
			Camera val10 = default(Camera);
			if ((Object)(object)val9 != (Object)null && val9.TryGetComponent<Camera>(ref val10))
			{
				val10.fieldOfView = Math.Min(106f / ((configUIAspect.Value > 0f) ? configUIAspect.Value : newAspect), 60f);
			}
			GameObject gameObject = ((Component)instance.Inventory.canvasGroup).gameObject;
			RectTransform val11 = default(RectTransform);
			if ((Object)(object)gameObject != (Object)null && gameObject.TryGetComponent<RectTransform>(ref val11))
			{
				val11.anchoredPosition = Vector2.zero;
				val11.anchorMax = new Vector2(0.5f, 0f);
				val11.anchorMin = new Vector2(0.5f, 0.5f);
				val11.pivot = new Vector2(0.5f, 0f);
			}
			GameObject val12 = GameObject.Find("PlayerHUDHelmetModel");
			Transform val13 = default(Transform);
			if ((Object)(object)val12 != (Object)null && val12.TryGetComponent<Transform>(ref val13))
			{
				Vector3 localScale = val13.localScale;
				localScale.x = fDefaultHelmetWidth * Math.Max(newAspect / 2.3f, 1f);
				val13.localScale = localScale;
			}
		}

		[HarmonyPatch(typeof(HUDManager), "Start")]
		[HarmonyPostfix]
		private static void HUDManagerStart(HUDManager __instance)
		{
			if (!aspectAutoDetect)
			{
				ChangeAspectRatio(1.77f);
			}
			prevAspect = 0f;
			prevTime = 0f;
		}

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		private static void HUDManagerUpdate(HUDManager __instance)
		{
			//IL_0024: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (aspectAutoDetect && Time.time > prevTime + aspectUpdateTime)
			{
				Vector2 renderingDisplaySize = ((Graphic)__instance.playerScreenTexture).canvas.renderingDisplaySize;
				float num = renderingDisplaySize.x / renderingDisplaySize.y;
				if (!Mathf.Approximately(num, prevAspect))
				{
					ChangeAspectRatio(num);
					prevAspect = num;
					Debug.Log((object)("New Aspect Ratio: " + num));
				}
				prevTime = Time.time;
			}
		}

		[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
		[HarmonyPostfix]
		private static void HUDManagerUpdateScanNodes(PlayerControllerB playerScript, HUDManager __instance, Dictionary<RectTransform, ScanNodeProperties> ___scanNodes)
		{
			//IL_001d: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform[] scanElements = __instance.scanElements;
			RectTransform val = default(RectTransform);
			if (!((Component)__instance.playerScreenTexture).gameObject.TryGetComponent<RectTransform>(ref val))
			{
				return;
			}
			Rect rect = val.rect;
			for (int i = 0; i < scanElements.Length; i++)
			{
				if (___scanNodes.TryGetValue(scanElements[i], out var value))
				{
					Vector3 val2 = playerScript.gameplayCamera.WorldToViewportPoint(((Component)value).transform.position);
					scanElements[i].anchoredPosition = new Vector2(((Rect)(ref rect)).xMin + ((Rect)(ref rect)).width * val2.x, ((Rect)(ref rect)).yMin + ((Rect)(ref rect)).height * val2.y);
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCUltrawide";

		public const string PLUGIN_NAME = "LCUltrawide";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}