Decompiled source of CustomResolution v0.1.0

Tomatobird.CustomResolution.dll

Decompiled 7 hours 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.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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Tomatobird.CustomResolution")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+40c50734896b985ce32106e49a442b1620cedda1")]
[assembly: AssemblyProduct("LC_CustomResolution")]
[assembly: AssemblyTitle("Tomatobird.CustomResolution")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.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.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;
		}
	}
	[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 LC_CustomResolution
{
	[BepInPlugin("Tomatobird.CustomResolution", "LC_CustomResolution", "0.1.0")]
	public class LC_CustomResolution : BaseUnityPlugin
	{
		internal static Dictionary<int, int[]> resolutions = new Dictionary<int, int[]>
		{
			{
				0,
				new int[2] { 860, 520 }
			},
			{
				1,
				new int[2] { 620, 364 }
			},
			{
				2,
				new int[2] { 400, 260 }
			},
			{
				3,
				new int[2] { 186, 104 }
			}
		};

		internal static List<string> resolutionNames = new List<string> { "Default", "Performance", "Ultra Performance", "Retro" };

		public static LC_CustomResolution Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			for (int i = 0; i < 4; i++)
			{
				string value = ((BaseUnityPlugin)this).Config.Bind<string>($"Resolution {i}", "Name", resolutionNames[i], "Name of the resolution option").Value;
				resolutionNames[i] = value;
				int value2 = ((BaseUnityPlugin)this).Config.Bind<int>($"Resolution {i}", "Width", resolutions[i][0], "Resolution width").Value;
				int value3 = ((BaseUnityPlugin)this).Config.Bind<int>($"Resolution {i}", "Height", resolutions[i][1], "Resolution height").Value;
				resolutions[i] = new int[2] { value2, value3 };
			}
			Patch();
			Logger.LogInfo((object)"Tomatobird.CustomResolution v0.1.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.CustomResolution");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.CustomResolution";

		public const string PLUGIN_NAME = "LC_CustomResolution";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace LC_CustomResolution.Patches
{
	[HarmonyPatch(typeof(IngamePlayerSettings))]
	internal class IngamePlayerSettingsPatch
	{
		[HarmonyPatch("SetPixelResolution")]
		[HarmonyPostfix]
		internal static void SetPixelResolution_Postfix(IngamePlayerSettings __instance, int value)
		{
			switch (value)
			{
			case 3:
				((Texture)__instance.playerGameplayScreenTex).width = LC_CustomResolution.resolutions[3][0];
				((Texture)__instance.playerGameplayScreenTex).height = LC_CustomResolution.resolutions[3][1];
				break;
			case 2:
				((Texture)__instance.playerGameplayScreenTex).width = LC_CustomResolution.resolutions[2][0];
				((Texture)__instance.playerGameplayScreenTex).height = LC_CustomResolution.resolutions[2][1];
				break;
			case 1:
				((Texture)__instance.playerGameplayScreenTex).width = LC_CustomResolution.resolutions[1][0];
				((Texture)__instance.playerGameplayScreenTex).height = LC_CustomResolution.resolutions[1][1];
				break;
			case 0:
				((Texture)__instance.playerGameplayScreenTex).width = LC_CustomResolution.resolutions[0][0];
				((Texture)__instance.playerGameplayScreenTex).height = LC_CustomResolution.resolutions[0][1];
				break;
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start_Postfix(MenuManager __instance)
		{
			if (__instance.isInitScene)
			{
				return;
			}
			Transform obj = ((Component)__instance.menuAnimator).transform.Find("SettingsPanel/PixelRes");
			TMP_Dropdown val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Dropdown>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				for (int i = 0; i < 4; i++)
				{
					val.options[i].text = LC_CustomResolution.resolutionNames[i];
				}
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager))]
	internal class QuickMenuManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start_Postfix(QuickMenuManager __instance)
		{
			Transform obj = __instance.settingsPanel.transform.Find("PixelRes");
			TMP_Dropdown val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Dropdown>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				for (int i = 0; i < 4; i++)
				{
					val.options[i].text = LC_CustomResolution.resolutionNames[i];
				}
			}
		}
	}
}