using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MoreResolution")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreResolution")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("34f3b572-bc1d-48ee-b3bc-a3ea5505a064")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreResolution;
[BepInPlugin("cc.lymone.HoL.MoreResolution", "MoreResolution", "1.1.0")]
public class MoreResolution : BaseUnityPlugin
{
private static readonly List<List<int>> resolutions = new List<List<int>>
{
new List<int> { 640, 480 },
new List<int> { 800, 600 },
new List<int> { 1280, 720 },
new List<int> { 1280, 800 },
new List<int> { 1280, 960 },
new List<int> { 1400, 1050 },
new List<int> { 1440, 900 },
new List<int> { 1600, 900 },
new List<int> { 1600, 1200 },
new List<int> { 1680, 1050 },
new List<int> { 1920, 1080 },
new List<int> { 1920, 1200 },
new List<int> { 2560, 1440 },
new List<int> { 2560, 1600 },
new List<int> { 2880, 1800 },
new List<int> { 3200, 1800 },
new List<int> { 3440, 1440 },
new List<int> { 3840, 2160 },
new List<int> { 3840, 2400 },
new List<int> { 5120, 2880 },
new List<int> { 5120, 3200 },
new List<int> { 7680, 4320 }
};
private static readonly List<string> VSyncText = new List<string> { "垂直同步", "VSync" };
private static ConfigEntry<int> customResolution_width;
private static ConfigEntry<int> customResolution_height;
private static ConfigEntry<bool> onVSync;
private static bool custom_flag = false;
private void Start()
{
customResolution_width = ((BaseUnityPlugin)this).Config.Bind<int>("自定义分辨率 Custom Resolution", "宽度 width", 0, "自定义分辨率的宽度,0为取消");
customResolution_height = ((BaseUnityPlugin)this).Config.Bind<int>("自定义分辨率 Custom Resolution", "高度 height", 0, "自定义分辨率的高度,0为取消");
onVSync = ((BaseUnityPlugin)this).Config.Bind<bool>("配置 Config", "启用垂直同步 VSync On", true, "启用垂直同步,游戏本体默认开启");
Mainload.AllFenBData = resolutions;
if (customResolution_width.Value != 0 && customResolution_height.Value != 0)
{
custom_flag = true;
Mainload.AllFenBData.Insert(0, new List<int> { customResolution_width.Value, customResolution_height.Value });
}
Harmony.CreateAndPatchAll(typeof(MoreResolution), (string)null);
AllText.Text_UIA[11] = new List<string> { "全屏", "Fullscreen" };
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SetPanel), "Awake")]
public static void CreateFenB(SetPanel __instance)
{
//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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Expected O, but got Unknown
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
List<OptionData> list = new List<OptionData>();
if (custom_flag)
{
new OptionData().text = string.Concat(new List<string>
{
"* ",
customResolution_width.Value.ToString(),
"x",
customResolution_height.Value.ToString()
});
}
for (int i = (custom_flag ? 1 : 0); i < Mainload.AllFenBData.Count; i++)
{
int num = Mainload.AllFenBData[i][0];
Resolution currentResolution = Screen.currentResolution;
if (num > ((Resolution)(ref currentResolution)).width)
{
break;
}
int num2 = Mainload.AllFenBData[i][0];
currentResolution = Screen.currentResolution;
if (num2 == ((Resolution)(ref currentResolution)).width)
{
int num3 = Mainload.AllFenBData[i][1];
currentResolution = Screen.currentResolution;
if (num3 > ((Resolution)(ref currentResolution)).height)
{
break;
}
}
OptionData item = new OptionData
{
text = string.Join("x", Mainload.AllFenBData[i])
};
list.Add(item);
}
((Component)((Component)__instance).transform.Find("FenB").Find("AllClass")).GetComponent<Dropdown>().options = list;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Mainload), "ReadSetData")]
public static bool LoadVSyncConfig()
{
VSyncSet(onVSync.Value);
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SaveData), "ReadSetData")]
public static bool ProtectFenBConfigPrefix(ref int __state)
{
try
{
List<int> list = ES3.Load<List<int>>("SetData", "FW/SetData.es3", Mainload.SetData);
__state = list[2];
}
catch (FormatException)
{
__state = -1;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SaveData), "ReadSetData")]
public static void ProtectFenBConfigPostfix(int __state)
{
if (__state != -1)
{
Mainload.SetData[2] = __state;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SetPanel), "Start")]
public static void CallCreateVSyncTogglePatch()
{
CreateVSyncToggle();
}
public static void CreateVSyncToggle()
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("SetPanel");
GameObject gameObject = ((Component)val.transform.Find("QuanP")).gameObject;
if ((Object)(object)val != (Object)null && (Object)(object)gameObject != (Object)null)
{
GameObject obj = Object.Instantiate<GameObject>(gameObject, val.transform);
((Object)obj).name = "VSync";
obj.transform.SetSiblingIndex(gameObject.transform.GetSiblingIndex() + 1);
((Component)obj.transform.Find("Tip")).GetComponent<Text>().text = VSyncText[Mainload.SetData[4]];
gameObject.transform.Translate(new Vector3(0f, 10f, 0f));
obj.transform.Translate(new Vector3(0f, -50f, 0f));
Toggle component = ((Component)obj.transform.Find("Toggle")).GetComponent<Toggle>();
((UnityEventBase)component.onValueChanged).RemoveAllListeners();
((UnityEvent<bool>)(object)component.onValueChanged).AddListener((UnityAction<bool>)VSyncSet);
component.isOn = onVSync.Value;
}
}
public static void VSyncSet(bool isOn)
{
onVSync.Value = isOn;
if (isOn)
{
QualitySettings.vSyncCount = 1;
}
else
{
QualitySettings.vSyncCount = 0;
}
}
}