Decompiled source of VSyncFeature v1.0.0

Mods/VSyncFeature.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UIElements;
using VSyncFeature;
using VSyncFeature.Tweaks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "VSyncFeature", "1.0.0", "Xannix", null)]
[assembly: MelonGame("Jan Malitschek", "BetonBrutal")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VSyncFeature")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VSyncFeature")]
[assembly: AssemblyTitle("VSyncFeature")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VSyncFeature
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(GameUI), "Awake")]
		private static class PatchGameUIAwake
		{
			[HarmonyPrefix]
			private static void Prefix(GameUI __instance)
			{
				Application.targetFrameRate = -1;
				((Component)__instance).gameObject.AddComponent<VSyncManager>().entry = entry;
				MelonLogger.Msg("VSync Mod Initialized.");
			}
		}

		private MelonPreferences_Category category;

		private static MelonPreferences_Entry<bool> entry;

		public override void OnInitializeMelon()
		{
			category = MelonPreferences.CreateCategory("vsyncPrefs");
			entry = category.CreateEntry<bool>("vsync", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		}
	}
}
namespace VSyncFeature.Tweaks
{
	internal class VSyncManager : MonoBehaviour
	{
		private readonly GameUI ui = GameObject.Find("GameUI").GetComponent<GameUI>();

		private Toggle vsyncToggle;

		public MelonPreferences_Entry<bool> entry;

		public void Start()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_006c: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			VisualElement val = UQueryExtensions.Q(UQueryExtensions.Q(ui.root, "Settings", (string)null), "RenderHalfResolutionSetting", (string)null);
			VisualElement parent = val.parent;
			int num = parent.IndexOf(val);
			Label val2 = new Label("Enable VSync");
			((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(20f);
			Label val3 = val2;
			Toggle val4 = new Toggle();
			((BaseField<bool>)val4).value = entry.Value;
			vsyncToggle = val4;
			INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)vsyncToggle, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> e)
			{
				ChangeVSync(e.newValue);
			});
			VisualElement val5 = new VisualElement();
			val5.style.flexGrow = StyleFloat.op_Implicit(1f);
			val5.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
			val5.style.backgroundColor = StyleColor.op_Implicit(new Color(0f, 0f, 0f, 0.7f));
			val5.style.marginTop = StyleLength.op_Implicit(2f);
			val5.style.marginLeft = StyleLength.op_Implicit(2f);
			VisualElement val6 = val5;
			VisualElement val7 = new VisualElement();
			val7.style.flexGrow = StyleFloat.op_Implicit(1f);
			val7.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
			VisualElement val8 = val7;
			val6.Add((VisualElement)(object)val3);
			val8.Add((VisualElement)(object)vsyncToggle);
			val6.Add(val8);
			parent.Insert(num + 1, val6);
			Initialize();
		}

		private void Initialize()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			QualitySettings.vSyncCount = 0;
			QualitySettings.vSyncCount = (entry.Value ? 1 : 0);
			UQueryExtensions.Q((VisualElement)(object)vsyncToggle, "unity-checkmark", (string)null).style.unityBackgroundImageTintColor = StyleColor.op_Implicit(entry.Value ? Color.white : Color.clear);
		}

		private void ChangeVSync(bool enabled)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			entry.Value = enabled;
			QualitySettings.vSyncCount = (enabled ? 1 : 0);
			UQueryExtensions.Q((VisualElement)(object)vsyncToggle, "unity-checkmark", (string)null).style.unityBackgroundImageTintColor = StyleColor.op_Implicit(enabled ? Color.white : Color.clear);
			MelonPreferences.Save();
		}
	}
}