Decompiled source of FixCameraResolution v1.0.2

Fix Camera Resolution.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Fix Camera Resolution")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Fix Camera Resolution")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dabb3c14-d069-4fdb-87ea-c7169dc3ef9e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace Rumi.FixCameraResolutions
{
	public class FCRConfig
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static EventHandler <>9__15_0;

			public static EventHandler <>9__15_1;

			public static EventHandler <>9__15_2;

			public static GenericButtonHandler <>9__16_0;

			internal void <.ctor>b__15_0(object sender, EventArgs e)
			{
				FCRPatches.AllTerminalPatch();
			}

			internal void <.ctor>b__15_1(object sender, EventArgs e)
			{
				FCRPatches.AllTerminalPatch();
			}

			internal void <.ctor>b__15_2(object sender, EventArgs e)
			{
				FCRPatches.AllTerminalPatch();
			}

			internal void <LethalConfigPatch>b__16_0()
			{
				FCRPatches.AllTerminalPatch();
			}
		}

		private readonly ConfigEntry<bool>? _autoSize;

		public const bool dAutoSize = true;

		private readonly ConfigEntry<int>? _width;

		public const int dWidth = 1920;

		private readonly ConfigEntry<int>? _height;

		public const int dHeight = 1080;

		public bool autoSize
		{
			get
			{
				return _autoSize?.Value ?? true;
			}
			set
			{
				if (_autoSize != null)
				{
					_autoSize.Value = value;
				}
			}
		}

		public int width
		{
			get
			{
				return _width?.Value ?? 1920;
			}
			set
			{
				if (_width != null)
				{
					_width.Value = value;
				}
			}
		}

		public int height
		{
			get
			{
				return _height?.Value ?? 1080;
			}
			set
			{
				if (_height != null)
				{
					_height.Value = value;
				}
			}
		}

		public FCRConfig(ConfigFile config)
		{
			_autoSize = config.Bind<bool>("General", "Auto Size", true, "When activated, sets the camera size to the size of the current game window.");
			_autoSize.SettingChanged += delegate
			{
				FCRPatches.AllTerminalPatch();
			};
			_width = config.Bind<int>("General", "Width", 1920, (ConfigDescription)null);
			_width.SettingChanged += delegate
			{
				FCRPatches.AllTerminalPatch();
			};
			_height = config.Bind<int>("General", "Height", 1080, (ConfigDescription)null);
			_height.SettingChanged += delegate
			{
				FCRPatches.AllTerminalPatch();
			};
			try
			{
				LethalConfigPatch();
			}
			catch (FileNotFoundException ex)
			{
				ManualLogSource? logger = FCRPlugin.logger;
				if (logger != null)
				{
					logger.LogError((object)ex);
				}
				ManualLogSource? logger2 = FCRPlugin.logger;
				if (logger2 != null)
				{
					logger2.LogWarning((object)"Lethal Config Patch Fail! (This is not a bug and occurs when LethalConfig is not present)");
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource? logger3 = FCRPlugin.logger;
				if (logger3 != null)
				{
					logger3.LogError((object)ex2);
				}
				ManualLogSource? logger4 = FCRPlugin.logger;
				if (logger4 != null)
				{
					logger4.LogError((object)"Lethal Config Patch Fail!");
				}
			}
		}

		private void LethalConfigPatch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0047: Expected O, but got Unknown
			//IL_004c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_006e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_008c: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(_autoSize, false));
			ConfigEntry<int>? obj = _width;
			IntSliderOptions val = new IntSliderOptions();
			((BaseRangeOptions<int>)val).Min = 1;
			((BaseRangeOptions<int>)val).Max = 3840;
			((BaseOptions)val).RequiresRestart = false;
			((BaseOptions)val).CanModifyCallback = new CanModifyDelegate(CanModifyAutoSize);
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj, val));
			ConfigEntry<int>? obj2 = _height;
			IntSliderOptions val2 = new IntSliderOptions();
			((BaseRangeOptions<int>)val2).Min = 1;
			((BaseRangeOptions<int>)val2).Max = 2160;
			((BaseOptions)val2).RequiresRestart = false;
			((BaseOptions)val2).CanModifyCallback = new CanModifyDelegate(CanModifyAutoSize);
			LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(obj2, val2));
			object obj3 = <>c.<>9__16_0;
			if (obj3 == null)
			{
				GenericButtonHandler val3 = delegate
				{
					FCRPatches.AllTerminalPatch();
				};
				<>c.<>9__16_0 = val3;
				obj3 = (object)val3;
			}
			LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem("General", "Refresh resolution", "If the resolution has been released for some reason, you can refresh it using this button.", "Refresh", (GenericButtonHandler)obj3));
		}

		private static CanModifyResult CanModifyAutoSize()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			FCRConfig? config = FCRPlugin.config;
			return CanModifyResult.op_Implicit((config == null || !config.autoSize, "Since auto size is enabled, the size is automatically set to the current game window size."));
		}
	}
	public class FCRPatches
	{
		public static int width
		{
			get
			{
				FCRConfig? config = FCRPlugin.config;
				if (config == null || config.autoSize)
				{
					return Screen.width;
				}
				return FCRPlugin.config?.width ?? 1920;
			}
		}

		public static int height
		{
			get
			{
				FCRConfig? config = FCRPlugin.config;
				if (config == null || config.autoSize)
				{
					return Screen.height;
				}
				return FCRPlugin.config?.height ?? 1080;
			}
		}

		public static int? orgWidth { get; private set; }

		public static int? orgHeight { get; private set; }

		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPostfix]
		private static void Terminal_Start_Postfix(Terminal __instance)
		{
			int? num = orgWidth;
			int valueOrDefault = num.GetValueOrDefault();
			if (!num.HasValue)
			{
				valueOrDefault = ((Texture)__instance.playerScreenTex).width;
				orgWidth = valueOrDefault;
			}
			num = orgHeight;
			valueOrDefault = num.GetValueOrDefault();
			if (!num.HasValue)
			{
				valueOrDefault = ((Texture)__instance.playerScreenTex).height;
				orgHeight = valueOrDefault;
			}
			RenderTexturePatch(__instance.playerScreenTex);
			RenderTexturePatch(__instance.playerScreenTexHighRes);
		}

		[HarmonyPatch(typeof(HUDManager), "UpdateScanNodes")]
		[HarmonyPostfix]
		private static void HUDManager_UpdateScanNodes_Postfix(HUDManager __instance)
		{
			//IL_0011: 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)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < __instance.scanElements.Length; i++)
			{
				RectTransform obj = __instance.scanElements[i];
				obj.anchoredPosition += new Vector2(439.48f, 244.8f);
				obj.anchoredPosition = obj.anchoredPosition.Multiply(((float?)orgWidth / (float)width).GetValueOrDefault(1f), ((float?)orgHeight / (float)height).GetValueOrDefault(1f));
				obj.anchoredPosition -= new Vector2(439.48f, 244.8f);
			}
		}

		public static void AllTerminalPatch()
		{
			Terminal[] array = Object.FindObjectsByType<Terminal>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				RenderTexturePatch(array[i].playerScreenTex);
				RenderTexturePatch(array[i].playerScreenTexHighRes);
			}
		}

		public static void RenderTexturePatch(RenderTexture renderTexture)
		{
			FCRConfig? config = FCRPlugin.config;
			int num;
			int num2;
			if (config == null || config.autoSize)
			{
				num = Screen.width;
				num2 = Screen.height;
			}
			else
			{
				num = FCRPlugin.config?.width ?? 1920;
				num2 = FCRPlugin.config?.height ?? 1080;
			}
			renderTexture.Release();
			((Texture)renderTexture).width = num;
			((Texture)renderTexture).height = num2;
			ManualLogSource? logger = FCRPlugin.logger;
			if (logger != null)
			{
				logger.LogInfo((object)$"Changed the size of the render texture to {num}x{num2}");
			}
		}
	}
	[BepInPlugin("Rumi.FixCameraResolutions", "FixCameraResolutions", "1.0.2")]
	public sealed class FCRPlugin : BaseUnityPlugin
	{
		public const string modGuid = "Rumi.FixCameraResolutions";

		public const string modName = "FixCameraResolutions";

		public const string modVersion = "1.0.2";

		public static ManualLogSource? logger { get; private set; }

		public static FCRConfig? config { get; private set; }

		public static Harmony harmony { get; } = new Harmony("Rumi.FixCameraResolutions");


		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			ManualLogSource? obj = logger;
			if (obj != null)
			{
				obj.LogInfo((object)"Start loading plugin...");
			}
			ManualLogSource? obj2 = logger;
			if (obj2 != null)
			{
				obj2.LogInfo((object)"Config Loading...");
			}
			try
			{
				config = new FCRConfig(((BaseUnityPlugin)this).Config);
			}
			catch (Exception ex)
			{
				config = null;
				ManualLogSource? obj3 = logger;
				if (obj3 != null)
				{
					obj3.LogError((object)ex);
				}
				ManualLogSource? obj4 = logger;
				if (obj4 != null)
				{
					obj4.LogWarning((object)"Failed to load config file\nSettings will be loaded with defaults!");
				}
			}
			ManualLogSource? obj5 = logger;
			if (obj5 != null)
			{
				obj5.LogInfo((object)"Patch...");
			}
			try
			{
				harmony.PatchAll(typeof(FCRPatches));
			}
			catch (Exception ex2)
			{
				ManualLogSource? obj6 = logger;
				if (obj6 != null)
				{
					obj6.LogError((object)ex2);
				}
				ManualLogSource? obj7 = logger;
				if (obj7 != null)
				{
					obj7.LogError((object)"Patch Fail!");
				}
			}
			ManualLogSource? obj8 = logger;
			if (obj8 != null)
			{
				obj8.LogInfo((object)"Plugin FixCameraResolutions is loaded!");
			}
		}
	}
	public static class FCRUtility
	{
		public static Vector2 Multiply(this Vector2 position, float x, float y)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(position.x * x, position.y * y);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}