Decompiled source of QuestGraphicsSettings v2.0.0

Mods/QuestGraphicsSettings.dll

Decompiled a day 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 BoneLib.BoneMenu;
using MelonLoader;
using MelonLoader.Preferences;
using QuestGraphicsSettings;
using Unity.XR.Oculus;
using UnityEngine;
using UnityEngine.Rendering.Universal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Core), "QuestGraphicsSettings", "2.0.0", "jorink", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("QuestGraphicsSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e6acf9701a0adea2ea86528fa599326a97d5cc41")]
[assembly: AssemblyProduct("QuestGraphicsSettings")]
[assembly: AssemblyTitle("QuestGraphicsSettings")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(8, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace QuestGraphicsSettings;

public class Core : MelonMod
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Action <>9__5_5;

		internal void <SetupBoneMenu>b__5_5()
		{
			MelonPreferences.Save();
		}
	}

	private const float ApplyRetryDurationSeconds = 10f;

	private const float ApplyRetryIntervalSeconds = 0.25f;

	private const float MaintenanceIntervalSeconds = 1f;

	private MelonPreferences_Category category;

	private MelonPreferences_Entry<float> RenderScaleEntry;

	private MelonPreferences_Entry<float> RenderDistanceEntry;

	private MelonPreferences_Entry<bool> DisableRenderDistanceTweaksEntry;

	private MelonPreferences_Entry<float> LODBiasEntry;

	private MelonPreferences_Entry<int> FFRLevelEntry;

	private int ffrLevel;

	private Camera playerCamera;

	private Camera defaultRenderDistanceCamera;

	private float defaultrenderdistance;

	private bool hasDefaultRenderDistance;

	private bool isApplyPending;

	private float applyRetryDeadline;

	private float nextApplyRetryAt;

	private float nextMaintenanceAt;

	private bool hasAppliedFfrLevel;

	private int lastAppliedFfrLevel;

	public override void OnInitializeMelon()
	{
		SetupMelonPreferences();
		SetupBoneMenu();
		QueueApplySettings();
	}

	public override void OnUpdate()
	{
		((MelonBase)this).OnUpdate();
		if (isApplyPending && Time.realtimeSinceStartup >= nextApplyRetryAt)
		{
			if (ApplySettings())
			{
				isApplyPending = false;
			}
			else if (Time.realtimeSinceStartup >= applyRetryDeadline)
			{
				isApplyPending = false;
				MelonLogger.Warning("QuestGraphicsSettings: not all settings could be applied before retry timeout.");
			}
			else
			{
				nextApplyRetryAt = Time.realtimeSinceStartup + 0.25f;
			}
		}
		if (Time.realtimeSinceStartup >= nextMaintenanceAt)
		{
			nextMaintenanceAt = Time.realtimeSinceStartup + 1f;
			ApplySettings();
		}
	}

	private void SetupBoneMenu()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Expected O, but got Unknown
		Page obj = Page.Root.CreatePage("Jorink", Color.magenta, 0, true).CreatePage("QuestGraphicsSettings", Color.red, 0, true);
		obj.CreateFloat("Render Scale", Color.yellow, RenderScaleEntry.Value, 0.05f, 0.5f, 2f, (Action<float>)([CompilerGenerated] (float a) =>
		{
			RenderScaleEntry.Value = a;
			SetRenderScale();
		}));
		obj.CreateFloat("Render Distance", Color.green, RenderDistanceEntry.Value, 5f, 5f, 300f, (Action<float>)([CompilerGenerated] (float a) =>
		{
			RenderDistanceEntry.Value = a;
			SetRenderDistance();
		}));
		obj.CreateBool("Disable Render Distance Tweaks", Color.cyan, DisableRenderDistanceTweaksEntry.Value, (Action<bool>)([CompilerGenerated] (bool a) =>
		{
			DisableRenderDistanceTweaksEntry.Value = a;
			SetRenderDistance();
		}));
		obj.CreateFloat("LOD Bias", Color.yellow, LODBiasEntry.Value, 0.05f, 0.5f, 2f, (Action<float>)([CompilerGenerated] (float a) =>
		{
			LODBiasEntry.Value = a;
			SetLODBias();
		}));
		obj.CreateInt("FFR Level", Color.green, FFRLevelEntry.Value, 1, 0, 3, (Action<int>)([CompilerGenerated] (int a) =>
		{
			FFRLevelEntry.Value = a;
			SetFFR();
		}));
		Color cyan = Color.cyan;
		object obj2 = <>c.<>9__5_5;
		if (obj2 == null)
		{
			Action val = delegate
			{
				MelonPreferences.Save();
			};
			<>c.<>9__5_5 = val;
			obj2 = (object)val;
		}
		obj.CreateFunction("Save Settings", cyan, (Action)obj2);
	}

	private void SetupMelonPreferences()
	{
		category = MelonPreferences.CreateCategory("QuestGraphicsSettings");
		RenderScaleEntry = category.CreateEntry<float>("Render Scale", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		RenderDistanceEntry = category.CreateEntry<float>("Render Distance", 100f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableRenderDistanceTweaksEntry = category.CreateEntry<bool>("Disable Render Distance Tweaks", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LODBiasEntry = category.CreateEntry<float>("LOD Bias", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FFRLevelEntry = category.CreateEntry<int>("FFR Level", 3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPreferences.Save();
		category.SaveToFile(true);
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
		QueueApplySettings();
	}

	private void QueueApplySettings()
	{
		isApplyPending = true;
		applyRetryDeadline = Time.realtimeSinceStartup + 10f;
		nextApplyRetryAt = Time.realtimeSinceStartup;
	}

	private bool ApplySettings()
	{
		bool num = SetRenderScale();
		bool flag = SetRenderDistance();
		bool flag2 = SetLODBias();
		bool flag3 = SetFFR();
		return num && flag && flag2 && flag3;
	}

	private bool SetRenderScale()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		UniversalRenderPipelineAsset asset = UniversalRenderPipeline.asset;
		if ((Object)asset == (Object)null)
		{
			return false;
		}
		asset.renderScale = RenderScaleEntry.Value;
		return true;
	}

	private bool SetRenderDistance()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_0056: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		if ((Object)playerCamera == (Object)null)
		{
			playerCamera = Object.FindObjectOfType<Camera>();
		}
		if ((Object)playerCamera == (Object)null)
		{
			return false;
		}
		if (!hasDefaultRenderDistance || (Object)defaultRenderDistanceCamera != (Object)playerCamera)
		{
			defaultRenderDistanceCamera = playerCamera;
			defaultrenderdistance = playerCamera.farClipPlane;
			hasDefaultRenderDistance = true;
		}
		if (DisableRenderDistanceTweaksEntry.Value)
		{
			playerCamera.farClipPlane = defaultrenderdistance;
			playerCamera.useOcclusionCulling = false;
			return true;
		}
		if ((Object)playerCamera != (Object)null)
		{
			playerCamera.farClipPlane = RenderDistanceEntry.Value;
			playerCamera.useOcclusionCulling = true;
			return true;
		}
		return false;
	}

	private bool SetLODBias()
	{
		QualitySettings.lodBias = LODBiasEntry.Value;
		return true;
	}

	private bool SetFFR()
	{
		ffrLevel = FFRLevelEntry.Value;
		if (!hasAppliedFfrLevel || lastAppliedFfrLevel != ffrLevel)
		{
			switch (ffrLevel)
			{
			case 0:
				MelonLogger.Msg("FFR: Level 0 (Off)");
				break;
			case 1:
				MelonLogger.Msg("FFR: Level 1 (Low)");
				break;
			case 2:
				MelonLogger.Msg("FFR: Level 2 (Medium)");
				break;
			case 3:
				MelonLogger.Msg("FFR: Level 3 (High)");
				break;
			}
		}
		Utils.useDynamicFoveatedRendering = false;
		Utils.foveatedRenderingLevel = ffrLevel;
		lastAppliedFfrLevel = ffrLevel;
		hasAppliedFfrLevel = true;
		return true;
	}
}