using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using QuestOptimizer;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Main), "Quest Optimizer", "1.0.0", "adama", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: HarmonyDontPatchAll]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace QuestOptimizer;
public class Main : MelonMod
{
public enum Foveation
{
Keep,
Off,
Low,
Medium,
High,
Highest
}
public enum Refresh
{
Keep,
Hz72,
Hz80,
Hz90,
Hz120
}
[CompilerGenerated]
private sealed class <Cameras>d__46 : global::System.Collections.Generic.IEnumerable<Camera>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<Camera>, global::System.IDisposable, global::System.Collections.IEnumerator
{
private int <>1__state;
private Camera <>2__current;
private int <>l__initialThreadId;
private Camera <main>5__2;
Camera global::System.Collections.Generic.IEnumerator<Camera>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object global::System.Collections.IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Cameras>d__46(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void global::System.IDisposable.Dispose()
{
}
private bool MoveNext()
{
Transform head;
Camera val;
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<main>5__2 = Camera.main;
if ((Object)(object)<main>5__2 != (Object)null)
{
<>2__current = <main>5__2;
<>1__state = 1;
return true;
}
goto IL_0057;
case 1:
<>1__state = -1;
goto IL_0057;
case 2:
{
<>1__state = -1;
break;
}
IL_0057:
head = Player.Head;
val = (((Object)(object)head != (Object)null) ? ((Component)head).GetComponent<Camera>() : null);
if ((Object)(object)val != (Object)null && ((Object)(object)<main>5__2 == (Object)null || ((Object)val).GetInstanceID() != ((Object)<main>5__2).GetInstanceID()))
{
<>2__current = val;
<>1__state = 2;
return true;
}
break;
}
return false;
}
bool global::System.Collections.IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void global::System.Collections.IEnumerator.Reset()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
throw new NotSupportedException();
}
[DebuggerHidden]
global::System.Collections.Generic.IEnumerator<Camera> global::System.Collections.Generic.IEnumerable<Camera>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <Cameras>d__46(0);
}
[DebuggerHidden]
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
{
return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<Camera>)this).GetEnumerator();
}
}
internal const string Version = "1.0.0";
private static MelonPreferences_Category _prefs;
private static MelonPreferences_Entry<bool> On;
private static MelonPreferences_Entry<bool> AutoRes;
private static MelonPreferences_Entry<bool> Shadows;
private static MelonPreferences_Entry<bool> Probes;
private static MelonPreferences_Entry<bool> Particles;
private static MelonPreferences_Entry<bool> Players;
private static MelonPreferences_Entry<float> Resolution;
private static MelonPreferences_Entry<float> MinResolution;
private static MelonPreferences_Entry<float> ViewDistance;
private static MelonPreferences_Entry<float> Detail;
private static MelonPreferences_Entry<float> LightDistance;
private static MelonPreferences_Entry<int> LightsPerThing;
private static MelonPreferences_Entry<int> Fov;
private static MelonPreferences_Entry<int> Hz;
internal static Instance Log;
private static float _scanAt;
private static float _lightsAt;
private static float _playersAt;
private static float _settleAt;
private static float _slowFor;
private static float _fastFor;
private static float _noRaiseUntil;
private static float _frame = 1f / 72f;
private static float _nextError;
private static float _scale = -1f;
private static bool _headsetDone;
private static UniversalRenderPipelineAsset _asset;
private static float _origScale = -1f;
private static float _origShadow = -1f;
private static float _origLod = -1f;
private static int _origLights = -1;
private static float _applied = -1f;
private static readonly Dictionary<int, float> _farPlanes = new Dictionary<int, float>();
private static readonly List<Light> _lights = new List<Light>();
private static readonly HashSet<int> _switchedOff = new HashSet<int>();
private static readonly Dictionary<int, LightShadows> _shadowsOff = new Dictionary<int, LightShadows>();
private static readonly List<Light> _shadowed = new List<Light>();
private static PropertyInfo _rate;
private static float _hz = 72f;
private static float _hzAt;
private static readonly Dictionary<string, global::System.Type> _types = new Dictionary<string, global::System.Type>();
public override void OnInitializeMelon()
{
Log = ((MelonBase)this).LoggerInstance;
_prefs = MelonPreferences.CreateCategory("QuestOptimizer");
On = _prefs.CreateEntry<bool>("On", true, "Optimize", (string)null, false, false, (ValueValidator)null, (string)null);
AutoRes = _prefs.CreateEntry<bool>("AutoResolution", true, "Lower the resolution when the game can't keep up, raise it when it can", (string)null, false, false, (ValueValidator)null, (string)null);
Resolution = _prefs.CreateEntry<float>("Resolution", 0.9f, "Resolution (the most, with auto resolution)", (string)null, false, false, (ValueValidator)null, (string)null);
MinResolution = _prefs.CreateEntry<float>("MinResolution", 0.6f, "The least resolution auto resolution goes to", (string)null, false, false, (ValueValidator)null, (string)null);
ViewDistance = _prefs.CreateEntry<float>("ViewDistance", 250f, "Nothing past this is drawn, in metres (0 = the map's own)", (string)null, false, false, (ValueValidator)null, (string)null);
Detail = _prefs.CreateEntry<float>("Detail", 0.7f, "Level of detail (lower = simpler models sooner; 1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
Shadows = _prefs.CreateEntry<bool>("RealtimeShadows", false, "Realtime shadows", (string)null, false, false, (ValueValidator)null, (string)null);
LightsPerThing = _prefs.CreateEntry<int>("LightsPerThing", 2, "The most realtime lights on any one thing", (string)null, false, false, (ValueValidator)null, (string)null);
LightDistance = _prefs.CreateEntry<float>("LightDistance", 30f, "Lights further than this are switched off, in metres (0 = never)", (string)null, false, false, (ValueValidator)null, (string)null);
Probes = _prefs.CreateEntry<bool>("FreezeReflections", true, "Reflection probes drawn once, not every frame", (string)null, false, false, (ValueValidator)null, (string)null);
Particles = _prefs.CreateEntry<bool>("CapParticles", true, "No effect makes more than 400 particles", (string)null, false, false, (ValueValidator)null, (string)null);
Players = _prefs.CreateEntry<bool>("CheaperPlayers", true, "Other players' bodies (Fusion) cost less to draw", (string)null, false, false, (ValueValidator)null, (string)null);
Fov = _prefs.CreateEntry<int>("Foveation", 4, "Fixed foveation (Quest): sharp in the middle, softer at the edges", (string)null, false, false, (ValueValidator)null, (string)null);
Hz = _prefs.CreateEntry<int>("RefreshRate", 0, "Headset refresh rate (Quest)", (string)null, false, false, (ValueValidator)null, (string)null);
Hooking.OnLevelLoaded += delegate
{
_scanAt = Time.unscaledTime + 2f;
_headsetDone = false;
};
}
public override void OnLateInitializeMelon()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Unknown result type (might be due to invalid IL or missing references)
Page obj = Page.Root.CreatePage("Quest Optimizer", new Color(0.4f, 1f, 0.6f), 0, true);
obj.CreateBool("Optimize", Color.white, On.Value, (Action<bool>)delegate(bool v)
{
On.Value = v;
Changed();
});
obj.CreateBool("Auto Resolution", Color.white, AutoRes.Value, (Action<bool>)delegate(bool v)
{
AutoRes.Value = v;
Changed();
});
obj.CreateFloat("Resolution", Color.white, Resolution.Value, 0.05f, 0.5f, 1f, (Action<float>)delegate(float v)
{
Resolution.Value = v;
Changed();
});
obj.CreateFloat("Lowest Auto Resolution", Color.white, MinResolution.Value, 0.05f, 0.5f, 1f, (Action<float>)delegate(float v)
{
MinResolution.Value = v;
Changed();
});
obj.CreateFloat("View Distance (m, 0 = map's)", Color.white, ViewDistance.Value, 25f, 0f, 1000f, (Action<float>)delegate(float v)
{
ViewDistance.Value = v;
Changed();
});
obj.CreateFloat("Detail", Color.white, Detail.Value, 0.1f, 0.2f, 2f, (Action<float>)delegate(float v)
{
Detail.Value = v;
Changed();
});
obj.CreateBool("Realtime Shadows", Color.white, Shadows.Value, (Action<bool>)delegate(bool v)
{
Shadows.Value = v;
Changed();
});
obj.CreateInt("Lights Per Thing", Color.white, LightsPerThing.Value, 1, 0, 8, (Action<int>)delegate(int v)
{
LightsPerThing.Value = v;
Changed();
});
obj.CreateFloat("Lights Off Past (m, 0 = never)", Color.white, LightDistance.Value, 5f, 0f, 150f, (Action<float>)delegate(float v)
{
LightDistance.Value = v;
Changed();
});
obj.CreateBool("Freeze Reflections", Color.white, Probes.Value, (Action<bool>)delegate(bool v)
{
Probes.Value = v;
Changed();
});
obj.CreateBool("Cap Particles", Color.white, Particles.Value, (Action<bool>)delegate(bool v)
{
Particles.Value = v;
Changed();
});
obj.CreateBool("Cheaper Players (Fusion)", Color.white, Players.Value, (Action<bool>)delegate(bool v)
{
Players.Value = v;
Changed();
});
obj.CreateEnum("Foveation", Color.white, (global::System.Enum)(Foveation)Math.Clamp(Fov.Value, 0, 5), (Action<global::System.Enum>)delegate(global::System.Enum v)
{
Fov.Value = Convert.ToInt32((object)v);
_headsetDone = false;
Save();
});
obj.CreateEnum("Refresh Rate", Color.white, (global::System.Enum)(Refresh)Math.Clamp(Hz.Value, 0, 4), (Action<global::System.Enum>)delegate(global::System.Enum v)
{
Hz.Value = Convert.ToInt32((object)v);
_headsetDone = false;
Save();
});
}
private static void Save()
{
_prefs.SaveToFile(false);
}
private static void Changed()
{
Save();
if (!On.Value)
{
Restore();
}
_scanAt = 0f;
_settleAt = 0f;
}
public override void OnUpdate()
{
if (!On.Value)
{
return;
}
try
{
float unscaledTime = Time.unscaledTime;
if (!_headsetDone)
{
_headsetDone = true;
Headset();
}
Resolve(unscaledTime);
if (unscaledTime >= _settleAt)
{
_settleAt = unscaledTime + 2f;
Settle();
}
if (unscaledTime >= _scanAt)
{
_scanAt = unscaledTime + 15f;
Scan();
}
if (unscaledTime >= _lightsAt)
{
_lightsAt = unscaledTime + 0.5f;
FarLights();
}
if (Players.Value && unscaledTime >= _playersAt)
{
_playersAt = unscaledTime + 4f;
CheapPlayers();
}
}
catch (global::System.Exception ex)
{
if (!(Time.unscaledTime < _nextError))
{
_nextError = Time.unscaledTime + 10f;
Log.Warning(ex.Message);
}
}
}
private static UniversalRenderPipelineAsset Asset()
{
if ((Object)(object)_asset != (Object)null)
{
return _asset;
}
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
_asset = (((Object)(object)currentRenderPipeline != (Object)null) ? ((Il2CppObjectBase)currentRenderPipeline).TryCast<UniversalRenderPipelineAsset>() : null);
return _asset;
}
private static void Resolve(float now)
{
float num = Math.Clamp(Resolution.Value, 0.5f, 1f);
float num2 = Math.Min(Math.Clamp(MinResolution.Value, 0.5f, 1f), num);
if (_scale < 0f)
{
_scale = num;
}
if (!AutoRes.Value)
{
SetScale(num);
return;
}
float unscaledDeltaTime = Time.unscaledDeltaTime;
_frame += (unscaledDeltaTime - _frame) * 0.05f;
float num3 = 1f / Math.Max(Rate(), 60f);
if (_frame > num3 * 1.18f)
{
_slowFor += unscaledDeltaTime;
_fastFor = 0f;
}
else if (_frame < num3 * 1.06f)
{
_fastFor += unscaledDeltaTime;
_slowFor = 0f;
}
if (_slowFor > 1.5f && _scale > num2 + 0.001f)
{
SetScale(Math.Max(num2, _scale - 0.05f));
_slowFor = 0f;
_noRaiseUntil = now + 30f;
}
else if (_fastFor > 10f && now >= _noRaiseUntil && _scale < num - 0.001f)
{
SetScale(Math.Min(num, _scale + 0.05f));
_fastFor = 0f;
}
if (_scale > num)
{
SetScale(num);
}
}
private static void SetScale(float scale)
{
_scale = scale;
if (Math.Abs(_applied - scale) < 0.001f)
{
return;
}
UniversalRenderPipelineAsset val = Asset();
if (!((Object)(object)val == (Object)null))
{
if (_origScale < 0f)
{
_origScale = val.renderScale;
}
val.renderScale = scale;
_applied = scale;
}
}
private static void Settle()
{
UniversalRenderPipelineAsset val = Asset();
if ((Object)(object)val != (Object)null)
{
if (_origShadow < 0f)
{
_origShadow = val.shadowDistance;
}
if (_origLights < 0)
{
_origLights = val.maxAdditionalLightsCount;
}
float num = (Shadows.Value ? _origShadow : 0f);
if (Math.Abs(val.shadowDistance - num) > 0.01f)
{
val.shadowDistance = num;
}
int num2 = Math.Clamp(LightsPerThing.Value, 0, 8);
if (val.maxAdditionalLightsCount != num2)
{
val.maxAdditionalLightsCount = num2;
}
}
if (_origLod < 0f)
{
_origLod = QualitySettings.lodBias;
}
float num3 = Math.Clamp(Detail.Value, 0.2f, 2f);
if (Math.Abs(QualitySettings.lodBias - num3) > 0.001f)
{
QualitySettings.lodBias = num3;
}
global::System.Collections.Generic.IEnumerator<Camera> enumerator = Cameras().GetEnumerator();
try
{
float num4 = default(float);
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
Camera current = enumerator.Current;
int instanceID = ((Object)current).GetInstanceID();
if (!_farPlanes.TryGetValue(instanceID, ref num4))
{
num4 = (_farPlanes[instanceID] = current.farClipPlane);
}
float num5 = ((ViewDistance.Value > 1f) ? Math.Min(num4, Math.Max(ViewDistance.Value, 20f)) : num4);
if (Math.Abs(current.farClipPlane - num5) > 0.01f)
{
current.farClipPlane = num5;
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
[IteratorStateMachine(typeof(<Cameras>d__46))]
private static global::System.Collections.Generic.IEnumerable<Camera> Cameras()
{
Camera main = Camera.main;
if ((Object)(object)main != (Object)null)
{
yield return main;
}
Transform head = Player.Head;
Camera val = (((Object)(object)head != (Object)null) ? ((Component)head).GetComponent<Camera>() : null);
if ((Object)(object)val != (Object)null && ((Object)(object)main == (Object)null || ((Object)val).GetInstanceID() != ((Object)main).GetInstanceID()))
{
yield return val;
}
}
private static void Scan()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Invalid comparison between Unknown and I4
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Invalid comparison between Unknown and I4
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Invalid comparison between Unknown and I4
_lights.Clear();
int num = 0;
int num2 = 0;
global::System.Collections.Generic.IEnumerator<Light> enumerator = Object.FindObjectsOfType<Light>().GetEnumerator();
try
{
LightShadows shadows = default(LightShadows);
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
Light current = enumerator.Current;
if (!((Object)(object)current == (Object)null) && !IsOurs(((Component)current).transform))
{
if ((int)current.type != 1)
{
_lights.Add(current);
}
int instanceID = ((Object)current).GetInstanceID();
if (!Shadows.Value && (int)current.shadows != 0)
{
_shadowsOff[instanceID] = current.shadows;
_shadowed.Add(current);
current.shadows = (LightShadows)0;
}
else if (Shadows.Value && _shadowsOff.TryGetValue(instanceID, ref shadows))
{
current.shadows = shadows;
_shadowsOff.Remove(instanceID);
}
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
if (Probes.Value)
{
global::System.Collections.Generic.IEnumerator<ReflectionProbe> enumerator2 = Object.FindObjectsOfType<ReflectionProbe>().GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator2).MoveNext())
{
ReflectionProbe current2 = enumerator2.Current;
if (!((Object)(object)current2 == (Object)null) && (int)current2.mode == 1 && (int)current2.refreshMode == 1)
{
current2.refreshMode = (ReflectionProbeRefreshMode)2;
current2.RenderProbe();
num++;
}
}
}
finally
{
((global::System.IDisposable)enumerator2)?.Dispose();
}
}
if (Particles.Value)
{
global::System.Collections.Generic.IEnumerator<ParticleSystem> enumerator3 = Object.FindObjectsOfType<ParticleSystem>().GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator3).MoveNext())
{
ParticleSystem current3 = enumerator3.Current;
if (!((Object)(object)current3 == (Object)null))
{
MainModule main = current3.main;
if (main.maxParticles > 400)
{
main.maxParticles = 400;
num2++;
}
}
}
}
finally
{
((global::System.IDisposable)enumerator3)?.Dispose();
}
}
if (num + num2 > 0)
{
Log.Msg($"Map tuned: {num} reflection probes frozen, {num2} effects capped, {_lights.Count} lights watched");
}
}
private static bool IsOurs(Transform t)
{
string name = ((Object)t.root).name;
if (!name.StartsWith("WigglesBW"))
{
return name.StartsWith("QuestDayNight");
}
return true;
}
private static void FarLights()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
Transform head = Player.Head;
if ((Object)(object)head == (Object)null)
{
return;
}
Vector3 position = head.position;
float value = LightDistance.Value;
for (int num = _lights.Count - 1; num >= 0; num--)
{
Light val = _lights[num];
if ((Object)(object)val == (Object)null)
{
_lights.RemoveAt(num);
}
else
{
int instanceID = ((Object)val).GetInstanceID();
int num2;
if (value > 1f)
{
Vector3 val2 = ((Component)val).transform.position - position;
num2 = ((((Vector3)(ref val2)).magnitude > value + val.range) ? 1 : 0);
}
else
{
num2 = 0;
}
bool flag = (byte)num2 != 0;
if (flag && ((Behaviour)val).enabled)
{
((Behaviour)val).enabled = false;
_switchedOff.Add(instanceID);
}
else if (!flag && !((Behaviour)val).enabled && _switchedOff.Remove(instanceID))
{
((Behaviour)val).enabled = true;
}
}
}
}
private static void CheapPlayers()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
RigManager rigManager = Player.RigManager;
int num = (((Object)(object)rigManager != (Object)null) ? ((Object)rigManager).GetInstanceID() : 0);
global::System.Collections.Generic.IEnumerator<RigManager> enumerator = Object.FindObjectsOfType<RigManager>().GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
RigManager current = enumerator.Current;
if ((Object)(object)current == (Object)null || ((Object)current).GetInstanceID() == num)
{
continue;
}
global::System.Collections.Generic.IEnumerator<SkinnedMeshRenderer> enumerator2 = ((Component)current).GetComponentsInChildren<SkinnedMeshRenderer>(true).GetEnumerator();
try
{
while (((global::System.Collections.IEnumerator)enumerator2).MoveNext())
{
SkinnedMeshRenderer current2 = enumerator2.Current;
if ((int)current2.quality != 2)
{
current2.quality = (SkinQuality)2;
}
if ((int)((Renderer)current2).shadowCastingMode != 0)
{
((Renderer)current2).shadowCastingMode = (ShadowCastingMode)0;
}
if (current2.updateWhenOffscreen)
{
current2.updateWhenOffscreen = false;
}
if (current2.skinnedMotionVectors)
{
current2.skinnedMotionVectors = false;
}
}
}
finally
{
((global::System.IDisposable)enumerator2)?.Dispose();
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
}
private static float Rate()
{
if (Time.unscaledTime < _hzAt)
{
return _hz;
}
_hzAt = Time.unscaledTime + 5f;
try
{
if (_rate == (PropertyInfo)null)
{
_rate = Find("OVRPlugin")?.GetProperty("systemDisplayFrequency", (BindingFlags)24);
}
_hz = ((_rate != (PropertyInfo)null && _rate.GetValue((object)null) is float num && num > 1f) ? num : 72f);
}
catch
{
_hz = 72f;
}
return _hz;
}
private static void Headset()
{
try
{
int num = Math.Clamp(Fov.Value, 0, 5);
if (num > 0)
{
PropertyInfo val = Find("OVRManager")?.GetProperty("fixedFoveatedRenderingLevel", (BindingFlags)24) ?? Find("OVRPlugin")?.GetProperty("fixedFoveatedRenderingLevel", (BindingFlags)24);
if (val != null)
{
val.SetValue((object)null, global::System.Enum.ToObject(val.PropertyType, num - 1));
}
PropertyInfo obj = Find("OVRManager")?.GetProperty("useDynamicFixedFoveatedRendering", (BindingFlags)24);
if (obj != null)
{
obj.SetValue((object)null, (object)false);
}
}
float[] array = new float[5];
RuntimeHelpers.InitializeArray((global::System.Array)array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
float num2 = array[Math.Clamp(Hz.Value, 0, 4)];
if (!(num2 > 0f))
{
return;
}
global::System.Type type = Find("OVRPlugin");
if (type != null)
{
PropertyInfo property = type.GetProperty("systemDisplayFrequency", (BindingFlags)24);
if (property != null)
{
property.SetValue((object)null, (object)num2);
}
}
}
catch (global::System.Exception ex)
{
Log.Msg("Headset settings not available here: " + ex.Message);
}
}
private static global::System.Type Find(string name)
{
global::System.Type type = default(global::System.Type);
if (_types.TryGetValue(name, ref type))
{
return type;
}
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly val in assemblies)
{
if (!val.GetName().Name.Contains("Oculus"))
{
continue;
}
try
{
type = Enumerable.FirstOrDefault<global::System.Type>((global::System.Collections.Generic.IEnumerable<global::System.Type>)val.GetTypes(), (Func<global::System.Type, bool>)((global::System.Type x) => ((MemberInfo)x).Name == name));
}
catch
{
type = null;
}
if (type != (global::System.Type)null)
{
break;
}
}
_types[name] = type;
return type;
}
private static void Restore()
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
UniversalRenderPipelineAsset val = Asset();
if ((Object)(object)val != (Object)null)
{
if (_origScale >= 0f)
{
val.renderScale = _origScale;
}
if (_origShadow >= 0f)
{
val.shadowDistance = _origShadow;
}
if (_origLights >= 0)
{
val.maxAdditionalLightsCount = _origLights;
}
}
_applied = -1f;
_scale = -1f;
if (_origLod >= 0f)
{
QualitySettings.lodBias = _origLod;
}
global::System.Collections.Generic.IEnumerator<Camera> enumerator = Cameras().GetEnumerator();
try
{
float farClipPlane = default(float);
while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
{
Camera current = enumerator.Current;
if (_farPlanes.TryGetValue(((Object)current).GetInstanceID(), ref farClipPlane))
{
current.farClipPlane = farClipPlane;
}
}
}
finally
{
((global::System.IDisposable)enumerator)?.Dispose();
}
Enumerator<Light> enumerator2 = _lights.GetEnumerator();
try
{
while (enumerator2.MoveNext())
{
Light current2 = enumerator2.Current;
if ((Object)(object)current2 != (Object)null && _switchedOff.Remove(((Object)current2).GetInstanceID()))
{
((Behaviour)current2).enabled = true;
}
}
}
finally
{
((global::System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
}
enumerator2 = _shadowed.GetEnumerator();
try
{
LightShadows shadows = default(LightShadows);
while (enumerator2.MoveNext())
{
Light current3 = enumerator2.Current;
if ((Object)(object)current3 != (Object)null && _shadowsOff.TryGetValue(((Object)current3).GetInstanceID(), ref shadows))
{
current3.shadows = shadows;
}
}
}
finally
{
((global::System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
}
_shadowsOff.Clear();
_shadowed.Clear();
}
}