Decompiled source of DisplayOptions v1.0.0

DisplayOptions.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BBModMenu;
using DisplayOptions;
using MelonLoader;
using UnityEngine;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(DisplayOptionsMod), "DisplayOptions", "1.0.0", "Bowilla", null)]
[assembly: MelonGame("", "Beton Brutal")]
[assembly: AssemblyTitle("DisplayOptions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DisplayOptions")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ebbe6483-dae8-4256-9125-1fd078fdb698")]
[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 DisplayOptions;

public class DisplayOptionsMod : MelonMod
{
	private int[] resolution = new int[2];

	private int[] custom_resolution = new int[2];

	private bool fullscreen;

	private string snapKey;

	public override void OnLateInitializeMelon()
	{
		MelonLogger.Msg("DisplayOptions starting to load.");
		GameObject val = GameObject.Find("GameUI");
		GameUI component = val.GetComponent<GameUI>();
		UIScreen? obj = ((typeof(GameUI)?.GetField("screens", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(component) is List<UIScreen> source) ? ((IEnumerable<UIScreen>)source).FirstOrDefault((Func<UIScreen, bool>)((UIScreen screen) => screen is ModMenu)) : null);
		ModMenu val2 = (ModMenu)(object)((obj is ModMenu) ? obj : null);
		if (val2 == null)
		{
			MelonLogger.Msg("ModMenu not found");
			return;
		}
		string text = "Display";
		VisualElement val3 = val2.AddSetting(text);
		Toggle val4 = val2.CreateToggle(text, "VSync", false);
		INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)val4, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> b)
		{
			QualitySettings.vSyncCount = (b.newValue ? 1 : 0);
		});
		Toggle val5 = val2.CreateToggle(text, "Fullscreen", Screen.fullScreen);
		INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)val5, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> b)
		{
			fullscreen = b.newValue;
		});
		Slider val6 = val2.CreateSlider(text, "Width", 160f, 3840f, (float)Screen.width, true);
		INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)val6, (EventCallback<ChangeEvent<float>>)delegate(ChangeEvent<float> f)
		{
			custom_resolution[0] = (int)f.newValue;
		});
		Slider val7 = val2.CreateSlider(text, "Height", 120f, 2160f, (float)Screen.height, true);
		INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)val7, (EventCallback<ChangeEvent<float>>)delegate(ChangeEvent<float> f)
		{
			custom_resolution[1] = (int)f.newValue;
		});
		VisualElement settingsGroup = val2.CreateGroup("Settings");
		VisualElement widthWrapper = val2.CreateWrapper();
		widthWrapper.Add((VisualElement)(object)val2.CreateLabel("Width"));
		widthWrapper.Add((VisualElement)(object)val6);
		VisualElement heightWrapper = val2.CreateWrapper();
		heightWrapper.Add((VisualElement)(object)val2.CreateLabel("Height"));
		heightWrapper.Add((VisualElement)(object)val7);
		List<string> list = new List<string>
		{
			"[8K UHD 16:9] 7680x4320", "[4K UHD 16:9] 3840x2160", "[WQXGA 16:10] 2560x1600", "[QHD 16:9] 2560x1440", "[QXGA 4:3] 2048x1536", "[WUXGA 16:10] 1920x1200", "[FHD 16:9] 1920x1080", "[WSXGA+ 16:10] 1680x1050", "[UXGA 4:3] 1600x1200", "[HD+ 16:9] 1600x900",
			"[WXGA+ 16:10] 1440x900", "[HD 16:9] 1366x768", "[WXGA 16:10] 1280x800", "[WXGA 16:9] 1280x720", "[XGA 4:3] 1024x768", "[SVGA 4:3] 800x600", "[VGA 4:3] 640x480", "[nHD 16:9] 640x360", "Custom Resolution"
		};
		Dictionary<string, int[]> resolutionValues = new Dictionary<string, int[]>
		{
			{
				"[8K UHD 16:9] 7680x4320",
				new int[2] { 7680, 4320 }
			},
			{
				"[4K UHD 16:9] 3840x2160",
				new int[2] { 3840, 2160 }
			},
			{
				"[WQXGA 16:10] 2560x1600",
				new int[2] { 2560, 1600 }
			},
			{
				"[QHD 16:9] 2560x1440",
				new int[2] { 2560, 1440 }
			},
			{
				"[QXGA 4:3] 2048x1536",
				new int[2] { 2048, 1536 }
			},
			{
				"[WUXGA 16:10] 1920x1200",
				new int[2] { 1920, 1200 }
			},
			{
				"[FHD 16:9] 1920x1080",
				new int[2] { 1920, 1080 }
			},
			{
				"[WSXGA+ 16:10] 1680x1050",
				new int[2] { 1680, 1050 }
			},
			{
				"[UXGA 4:3] 1600x1200",
				new int[2] { 1600, 1200 }
			},
			{
				"[HD+ 16:9] 1600x900",
				new int[2] { 1600, 900 }
			},
			{
				"[WXGA+ 16:10] 1440x900",
				new int[2] { 1440, 900 }
			},
			{
				"[HD 16:9] 1366x768",
				new int[2] { 1366, 768 }
			},
			{
				"[WXGA 16:10] 1280x800",
				new int[2] { 1280, 800 }
			},
			{
				"[WXGA 16:9] 1280x720",
				new int[2] { 1280, 720 }
			},
			{
				"[XGA 4:3] 1024x768",
				new int[2] { 1024, 768 }
			},
			{
				"[SVGA 4:3] 800x600",
				new int[2] { 800, 600 }
			},
			{
				"[VGA 4:3] 640x480",
				new int[2] { 640, 480 }
			},
			{
				"[nHD 16:9] 640x360",
				new int[2] { 640, 360 }
			},
			{
				"Custom Resolution",
				new int[2]
				{
					(int)((BaseField<float>)(object)val6).value,
					(int)((BaseField<float>)(object)val7).value
				}
			}
		};
		CarouselEntry val8 = val2.CreateCarousel(text, "ResolutionPresets", list, (Action<string>)delegate(string _key)
		{
			MelonLogger.Msg("Resolution preset changed to " + _key);
			resolutionValues.TryGetValue(_key, out var value2);
			resolution[0] = value2[0];
			resolution[1] = value2[1];
			if (_key == "Custom Resolution")
			{
				resolution = (custom_resolution = value2);
				settingsGroup.Add(widthWrapper);
				settingsGroup.Add(heightWrapper);
			}
			else
			{
				settingsGroup.Remove(widthWrapper);
				settingsGroup.Remove(heightWrapper);
			}
		}, "[FHD 16:9] 1920x1080");
		HotKeyEntry val9 = val2.CreateHotKey(text, "ResolutionSnapHotkey", (KeyCode)292);
		snapKey = val9.Value;
		val9.OnChanged = (Action<string>)Delegate.Combine(val9.OnChanged, (Action<string>)delegate(string newKey)
		{
			MelonLogger.Msg("Resolution Snap Hotkey : " + newKey);
			snapKey = newKey;
		});
		Button val10 = val2.CreateButton("Apply");
		val10.clicked += Apply;
		VisualElement val11 = val2.CreateWrapper();
		val11.Add((VisualElement)(object)val2.CreateLabel("Enable VSync"));
		val11.Add((VisualElement)(object)val4);
		VisualElement val12 = val2.CreateWrapper();
		val12.Add((VisualElement)(object)val2.CreateLabel("Enable Fullscreen"));
		val12.Add((VisualElement)(object)val5);
		VisualElement val13 = val2.CreateWrapper();
		val13.Add((VisualElement)(object)val2.CreateLabel("Resolution Presets"));
		val13.Add(val8.Root);
		VisualElement val14 = val2.CreateGroup("Apply");
		VisualElement val15 = val2.CreateWrapper();
		val15.Add((VisualElement)(object)val2.CreateLabel("Apply Resolution Settings"));
		val15.Add((VisualElement)(object)val10);
		VisualElement val16 = val2.CreateWrapper();
		val16.Add((VisualElement)(object)val2.CreateLabel("Resolution Snap Hotkey"));
		val16.Add(val9.Root);
		settingsGroup.Add(val11);
		settingsGroup.Add(val12);
		settingsGroup.Add(val13);
		val14.Add(val15);
		val14.Add(val16);
		val3.Add(settingsGroup);
		val3.Add(val14);
		resolutionValues.TryGetValue(val8.Value, out var value);
		resolution[0] = value[0];
		resolution[1] = value[1];
		if (val8.Value == "Custom Resolution")
		{
			custom_resolution = value;
			settingsGroup.Add(widthWrapper);
			settingsGroup.Add(heightWrapper);
		}
		fullscreen = ((BaseField<bool>)(object)val5).value;
		Apply();
		QualitySettings.vSyncCount = (((BaseField<bool>)(object)val4).value ? 1 : 0);
	}

	private void Apply()
	{
		string arg = (fullscreen ? "fullscreen" : "windowed");
		MelonLogger.Msg($"Resolution: {resolution[0]}x{resolution[1]} {arg}");
		Screen.SetResolution(resolution[0], resolution[1], fullscreen);
	}

	public override void OnUpdate()
	{
		if (Utils.IsHotkeyPressed(snapKey))
		{
			Apply();
		}
	}
}