using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SettingsMenu.Components.Pages;
using UkResolution.patches;
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("UkResolution")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c489ab850fc2a93deb8a34b091417b512283938c")]
[assembly: AssemblyProduct("UkResolution")]
[assembly: AssemblyTitle("UkResolution")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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 UkResolution
{
[BepInPlugin("pozdro.ultrakill.ukresolution", "Uk Resolution", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private ConfigFile mainCFG;
private ConfigEntry<KeyboardShortcut> resetResKeybind;
private ConfigEntry<string> resetResRes;
private void Awake()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
mainCFG = new ConfigFile(Path.Combine(Paths.ConfigPath, "UkResolution", "UKResolution.cfg"), true);
ResolutionPatch.Initialize();
Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, (string)null);
resetResKeybind = mainCFG.Bind<KeyboardShortcut>("Keybinds", "Resolution Reset Keybind", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Keybind for resetting resolution");
resetResRes = mainCFG.Bind<string>("Keybinds", "Resolution Reset Resolution", "1920 x 1080", "Resolution that should be set after pressing reset keybind");
Log.LogInfo((object)"Plugin Uk Resolution is loaded!");
}
private void Update()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
KeyboardShortcut value = resetResKeybind.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
Log.LogInfo((object)"Reset keybind pressed!");
string[] array = resetResRes.Value.Split('x');
if (array.Length != 2 || !int.TryParse(array[0].Trim(), out var result) || !int.TryParse(array[1].Trim(), out var result2))
{
Log.LogError((object)("Invalid resolution format: " + resetResRes.Value));
return;
}
Screen.SetResolution(result, result2, (FullScreenMode)1);
Log.LogInfo((object)$"Resetting resolution to: {result} x {result2}");
}
}
}
internal static class PluginConfigManager
{
private static readonly string configPath = Path.Combine(Paths.ConfigPath, "UkResolution", "UKRResolutions.cfg");
private static void CheckConfigIntegrity()
{
if (File.Exists(Path.Combine(Paths.ConfigPath, "UkResolution.cfg")))
{
File.Delete(Path.Combine(Paths.ConfigPath, "UkResolution.cfg"));
Plugin.Log.LogInfo((object)"Found old config file, removing...");
}
if (!File.Exists(configPath))
{
Plugin.Log.LogInfo((object)"UKResolutionConfig not found, creating...");
File.WriteAllText(configPath, "[Resolutions]\r\n640 x 480\r\n720 x 480\r\n800 x 480\r\n800 x 600\r\n1024 x 768\r\n1280 x 720\r\n1280 x 800\r\n1280 x 1024\r\n1366 x 768\r\n1440 x 900\r\n1600 x 900\r\n1600 x 1200\r\n1680 x 1050\r\n1920 x 1080\r\n1920 x 1200\r\n2048 x 1080\r\n2560 x 1080\r\n2560 x 1440\r\n2560 x 1600\r\n2880 x 1800\r\n3200 x 1800\r\n3440 x 1440\r\n3840 x 1600\r\n3840 x 2160\r\n4096 x 2160\r\n5120 x 1440\r\n5120 x 2160\r\n5120 x 2880\r\n6016 x 3384\r\n7680 x 4320\r\n8192 x 4320");
Plugin.Log.LogInfo((object)("Created " + configPath));
}
}
private static List<string> GetConfigPart(string part, out List<int> lineIndex)
{
CheckConfigIntegrity();
string[] array = File.ReadAllLines(configPath);
bool flag = false;
List<string> list = new List<string>();
lineIndex = new List<int>();
string[] array2 = array;
foreach (string text in array2)
{
string text2 = text.Trim();
if (string.IsNullOrWhiteSpace(text2) || text2.StartsWith("#"))
{
continue;
}
if (text2.StartsWith("["))
{
if (flag)
{
break;
}
flag = false;
if (text2.Equals(part))
{
flag = true;
}
}
else if (flag)
{
list.Add(text2);
lineIndex.Add(Array.IndexOf(array, text));
}
}
return list;
}
public static List<Resolution> LoadConfigResolutions()
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
CheckConfigIntegrity();
List<Resolution> list = new List<Resolution>();
List<int> lineIndex;
List<string> configPart = GetConfigPart("[Resolutions]", out lineIndex);
foreach (string item2 in configPart)
{
string[] array = item2.Split('x');
if (array.Length != 2)
{
Plugin.Log.LogWarning((object)("Invalid resolution: " + item2));
continue;
}
if (!int.TryParse(array[0].Trim(), out var result))
{
Plugin.Log.LogWarning((object)("Invalid width: " + item2));
continue;
}
if (!int.TryParse(array[1].Trim(), out var result2))
{
Plugin.Log.LogWarning((object)("Invalid height: " + item2));
continue;
}
Resolution val = default(Resolution);
((Resolution)(ref val)).width = result;
((Resolution)(ref val)).height = result2;
((Resolution)(ref val)).refreshRateRatio = new RefreshRate
{
numerator = 60u,
denominator = 1u
};
Resolution item = val;
list.Add(item);
}
return list;
}
}
}
namespace UkResolution.patches
{
[HarmonyPatch]
public static class ResolutionPatch
{
internal static List<Resolution> resolutions = new List<Resolution>();
public static void Initialize()
{
resolutions = PluginConfigManager.LoadConfigResolutions();
Plugin.Log.LogInfo((object)$"Loaded {resolutions.Count} resolutions from config.");
}
[HarmonyPatch(typeof(GraphicsSettings), "GetAvailableResolutions")]
[HarmonyPostfix]
private static void GetAvailableResolutions(GraphicsSettings __instance)
{
//IL_003c: 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_0044: Unknown result type (might be due to invalid IL or missing references)
FieldInfo field = typeof(GraphicsSettings).GetField("availableResolutions", BindingFlags.Instance | BindingFlags.NonPublic);
List<(Resolution, string)> list = (List<(Resolution, string)>)field.GetValue(__instance);
list.Clear();
foreach (Resolution resolution in resolutions)
{
Resolution current = resolution;
list.Add((current, $"{((Resolution)(ref current)).width} x {((Resolution)(ref current)).height}"));
}
}
[HarmonyPatch(typeof(GraphicsSettings), "SetResolution")]
[HarmonyPostfix]
private static void CheckResolution()
{
Plugin.Log.LogInfo((object)$"Resolution set to: {Screen.width} x {Screen.height}");
}
}
}