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 UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Boxofbiscuits97.BetterOptions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+e8b0de86f7f1b4074ca7110284e9f6e87b692e55")]
[assembly: AssemblyProduct("com.github.Boxofbiscuits97.BetterOptions")]
[assembly: AssemblyTitle("BetterOptions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BetterOptions
{
[BepInPlugin("com.github.Boxofbiscuits97.BetterOptions", "BetterOptions", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(OptionsScreen), "Start")]
private class OptionsScreenStartPatch
{
private static void Postfix(OptionsScreen __instance)
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
__instance.filteredResolutions.Clear();
int systemWidth = Display.main.systemWidth;
int systemHeight = Display.main.systemHeight;
Log.LogInfo((object)$"Found system resolution: {systemWidth}x{systemHeight}");
ResItem val = new ResItem();
val.horizontal = systemWidth;
val.vertical = systemHeight;
if (!ResolutionExists(__instance.resolutions, val))
{
__instance.resolutions.Add(val);
__instance.selectedResolution = __instance.resolutions.Count - 1;
__instance.UpdateResLabel();
}
foreach (ResItem resolution in __instance.resolutions)
{
if (resolution.horizontal <= systemWidth && !ResolutionExists(__instance.filteredResolutions, resolution))
{
__instance.filteredResolutions.Add(resolution);
Log.LogInfo((object)$"Added resolution {resolution.horizontal}x{resolution.vertical} to filtered resolutions");
}
}
}
}
[HarmonyPatch(typeof(OptionsScreen), "ApplyGraphics")]
private class OptionsScreenApplyGraphicsPatch
{
private static void Postfix(OptionsScreen __instance)
{
int num = (__instance.vsyncTog.isOn ? 1 : 0);
int num2 = (__instance.fullscreenTog.isOn ? 1 : 0);
int horizontal = __instance.filteredResolutions[__instance.selectedResolution].horizontal;
int vertical = __instance.filteredResolutions[__instance.selectedResolution].vertical;
Log.LogInfo((object)$"Saving graphics settings to PlayerPrefs: vSync: {num}, Fullscreen: {num2}, Resolution: {horizontal}x{vertical}");
PlayerPrefs.SetInt("VsyncEnabled", num);
PlayerPrefs.SetInt("FullscreenEnabled", num2);
PlayerPrefs.SetInt("ResolutionWidth", horizontal);
PlayerPrefs.SetInt("ResolutionHeight", vertical);
}
}
public const string Id = "com.github.Boxofbiscuits97.BetterOptions";
internal static ManualLogSource Log { get; private set; }
public static string Name => "BetterOptions";
public static string Version => "0.1.1";
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(OptionsScreenApplyGraphicsPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(OptionsScreenStartPatch), (string)null);
SceneManager.sceneLoaded += MainMenuLoaded;
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
}
private void MainMenuLoaded(Scene scene, LoadSceneMode mode)
{
if (!(((Scene)(ref scene)).name != "StartScene"))
{
if (PlayerPrefs.HasKey("VsyncEnabled"))
{
int @int = PlayerPrefs.GetInt("VsyncEnabled");
bool flag = @int == 1;
QualitySettings.vSyncCount = @int;
Log.LogInfo((object)$"VSync enabled: {flag}");
}
if (PlayerPrefs.HasKey("FullscreenEnabled"))
{
int int2 = PlayerPrefs.GetInt("FullscreenEnabled");
bool flag3 = (Screen.fullScreen = int2 == 1);
Log.LogInfo((object)$"Fullscreen enabled: {flag3}");
}
if (PlayerPrefs.HasKey("ResolutionWidth") && PlayerPrefs.HasKey("ResolutionHeight"))
{
int int3 = PlayerPrefs.GetInt("ResolutionWidth");
int int4 = PlayerPrefs.GetInt("ResolutionHeight");
Screen.SetResolution(int3, int4, Screen.fullScreen);
Log.LogInfo((object)$"Resolution set to: {int3}x{int4}");
}
}
}
public static bool ResolutionExists(List<ResItem> resolutions, ResItem checkResolution)
{
foreach (ResItem resolution in resolutions)
{
if (resolution.horizontal == checkResolution.horizontal && resolution.vertical == checkResolution.vertical)
{
return true;
}
}
return false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}