Decompiled source of BoneFPS v1.0.5

Mods/BoneFPS.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneFPS;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Scripting;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(BoneFpsMod), "BoneFPS", "2.0.5", "you", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "BoneLib", "LabFusion" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BoneFPS")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoneFPS")]
[assembly: AssemblyTitle("BoneFPS")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BoneFPS;

public sealed class BoneFpsMod : MelonMod
{
	private struct SpawnRequest
	{
		public string PrefabPath;

		public Vector3 Position;

		public Quaternion Rotation;

		public Action<GameObject> Callback;

		public int Priority;

		public float RequestTime;
	}

	[CompilerGenerated]
	private sealed class <BackgroundOptimizationLoop>d__281 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <BackgroundOptimizationLoop>d__281(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				if (Enabled.Value)
				{
					<>4__this.CleanupNullReferences();
					<>4__this.UpdateBoundsCache();
					if (MemoryPooling.Value && Time.frameCount % 300 == 0)
					{
						<>4__this.DoMemoryOptimization();
					}
				}
				break;
			}
			<>2__current = (object)new WaitForSeconds(5f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <PreloadAudio>d__278 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		private Il2CppArrayBase<AudioClip> <clips>5__1;

		private int <count>5__2;

		private IEnumerator<AudioClip> <>s__3;

		private AudioClip <clip>5__4;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <PreloadAudio>d__278(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<clips>5__1 = null;
			<>s__3 = null;
			<clip>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			try
			{
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -3;
					goto IL_00ea;
				}
				<>1__state = -1;
				<clips>5__1 = Resources.FindObjectsOfTypeAll<AudioClip>();
				<count>5__2 = 0;
				<>s__3 = <clips>5__1.GetEnumerator();
				<>1__state = -3;
				goto IL_00f2;
				IL_00ea:
				<clip>5__4 = null;
				goto IL_00f2;
				IL_00f2:
				do
				{
					if (<>s__3.MoveNext())
					{
						<clip>5__4 = <>s__3.Current;
						continue;
					}
					<>m__Finally1();
					<>s__3 = null;
					return false;
				}
				while ((Object)(object)<clip>5__4 == (Object)null);
				try
				{
					if ((int)<clip>5__4.loadState != 2)
					{
						<clip>5__4.LoadAudioData();
					}
				}
				catch
				{
				}
				<count>5__2++;
				if (<count>5__2 % 20 == 0)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				goto IL_00ea;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<>s__3 != null)
			{
				<>s__3.Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <PreloadLevelAssets>d__276 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <PreloadLevelAssets>d__276(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				if (!LoadingOptimization.Value)
				{
					return false;
				}
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if (ShaderWarmup.Value)
				{
					try
					{
						Shader.WarmupAllShaders();
					}
					catch
					{
					}
				}
				<>2__current = null;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				if (TexturePreload.Value)
				{
					MelonCoroutines.Start(<>4__this.PreloadTextures());
				}
				if (AudioPreload.Value)
				{
					MelonCoroutines.Start(<>4__this.PreloadAudio());
				}
				if (AssetBundleCaching.Value)
				{
					<>4__this.OptimizeAssetBundles();
				}
				if (Log.Value)
				{
					MelonLogger.Msg("[BoneFPS] Level assets preloaded");
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <PreloadTextures>d__277 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		private Il2CppArrayBase<Texture2D> <textures>5__1;

		private int <count>5__2;

		private IEnumerator<Texture2D> <>s__3;

		private Texture2D <tex>5__4;

		private int <_>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <PreloadTextures>d__277(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<textures>5__1 = null;
			<>s__3 = null;
			<tex>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			try
			{
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -3;
					goto IL_00d6;
				}
				<>1__state = -1;
				<textures>5__1 = Resources.FindObjectsOfTypeAll<Texture2D>();
				<count>5__2 = 0;
				<>s__3 = <textures>5__1.GetEnumerator();
				<>1__state = -3;
				goto IL_00de;
				IL_00d6:
				<tex>5__4 = null;
				goto IL_00de;
				IL_00de:
				do
				{
					if (<>s__3.MoveNext())
					{
						<tex>5__4 = <>s__3.Current;
						continue;
					}
					<>m__Finally1();
					<>s__3 = null;
					return false;
				}
				while ((Object)(object)<tex>5__4 == (Object)null);
				try
				{
					<_>5__5 = ((Texture)<tex>5__4).width;
				}
				catch
				{
				}
				<count>5__2++;
				if (<count>5__2 % 50 == 0)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				goto IL_00d6;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<>s__3 != null)
			{
				<>s__3.Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <PrewarmObjectPools>d__269 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <PrewarmObjectPools>d__269(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(2f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if (ShaderWarmup.Value)
				{
					try
					{
						Shader.WarmupAllShaders();
					}
					catch
					{
					}
				}
				if (Log.Value)
				{
					MelonLogger.Msg("[BoneFPS] Object pools prewarmed");
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <RebuildCachesDelayed>d__286 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public BoneFpsMod <>4__this;

		private IEnumerator<GameObject> <>s__1;

		private GameObject <go>5__2;

		private Il2CppArrayBase<Component> <components>5__3;

		private IEnumerator<Component> <>s__4;

		private Component <comp>5__5;

		private string <typeName>5__6;

		private IEnumerator<GameObject> <>s__7;

		private GameObject <go>5__8;

		private Transform <root>5__9;

		private List<Component>.Enumerator <>s__10;

		private Component <rb>5__11;

		private string <rootName>5__12;

		private Exception <ex>5__13;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <RebuildCachesDelayed>d__286(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>s__1 = null;
			<go>5__2 = null;
			<components>5__3 = null;
			<>s__4 = null;
			<comp>5__5 = null;
			<typeName>5__6 = null;
			<>s__7 = null;
			<go>5__8 = null;
			<root>5__9 = null;
			<>s__10 = default(List<Component>.Enumerator);
			<rb>5__11 = null;
			<rootName>5__12 = null;
			<ex>5__13 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 3;
				return true;
			case 3:
				<>1__state = -1;
				<>4__this.ClearAllCaches();
				try
				{
					<>4__this._renderers.AddRange((IEnumerable<Renderer>)Object.FindObjectsOfType<Renderer>(true));
					<>4__this._lights.AddRange((IEnumerable<Light>)Object.FindObjectsOfType<Light>(true));
					<>4__this._audio.AddRange((IEnumerable<AudioSource>)Object.FindObjectsOfType<AudioSource>(true));
					<>4__this._cameras.AddRange((IEnumerable<Camera>)Object.FindObjectsOfType<Camera>(true));
					<>4__this._animators.AddRange((IEnumerable<Component>)Object.FindObjectsOfType<Animator>(true));
					<>4__this._rigidbodies.AddRange(<>4__this.SafeFindAllOfType("Rigidbody"));
					<>4__this._particles.AddRange(<>4__this.SafeFindAllOfType("ParticleSystem"));
					<>4__this._reflectionProbes.AddRange((IEnumerable<Component>)Object.FindObjectsOfType<ReflectionProbe>(true));
					<>4__this._navMeshAgents.AddRange(<>4__this.SafeFindAllOfType("NavMeshAgent"));
					<>4__this._cloths.AddRange(<>4__this.SafeFindAllOfType("Cloth"));
					<>4__this._trailRenderers.AddRange(<>4__this.SafeFindAllOfType("TrailRenderer"));
					<>4__this._lineRenderers.AddRange(<>4__this.SafeFindAllOfType("LineRenderer"));
					<>4__this._lodGroups.AddRange((IEnumerable<Component>)Object.FindObjectsOfType<LODGroup>(true));
					<>4__this._colliders.AddRange(<>4__this.SafeFindAllOfType("Collider"));
					<>4__this._joints.AddRange(<>4__this.SafeFindAllOfType("Joint"));
					<>s__1 = Object.FindObjectsOfType<GameObject>(true).GetEnumerator();
					try
					{
						while (<>s__1.MoveNext())
						{
							<go>5__2 = <>s__1.Current;
							<components>5__3 = <go>5__2.GetComponents<Component>();
							<>s__4 = <components>5__3.GetEnumerator();
							try
							{
								while (<>s__4.MoveNext())
								{
									<comp>5__5 = <>s__4.Current;
									if (!((Object)(object)<comp>5__5 == (Object)null))
									{
										<typeName>5__6 = ((object)<comp>5__5).GetType().Name;
										if (<typeName>5__6.Contains("IK") || <typeName>5__6.Contains("Solver"))
										{
											<>4__this._ikSolvers.Add(<comp>5__5);
										}
										if (<typeName>5__6.Contains("Constraint"))
										{
											<>4__this._constraintComponents.Add(<comp>5__5);
										}
										<typeName>5__6 = null;
										<comp>5__5 = null;
									}
								}
							}
							finally
							{
								if (<>s__4 != null)
								{
									<>s__4.Dispose();
								}
							}
							<>s__4 = null;
							<components>5__3 = null;
							<go>5__2 = null;
						}
					}
					finally
					{
						if (<>s__1 != null)
						{
							<>s__1.Dispose();
						}
					}
					<>s__1 = null;
					<>s__7 = Object.FindObjectsOfType<GameObject>(true).GetEnumerator();
					try
					{
						while (<>s__7.MoveNext())
						{
							<go>5__8 = <>s__7.Current;
							if (((Object)<go>5__8).name.Contains("NPC") || ((Object)<go>5__8).name.Contains("Enemy") || ((Object)<go>5__8).name.Contains("AI") || ((Object)<go>5__8).name.Contains("Null"))
							{
								<root>5__9 = <go>5__8.transform.root;
								if ((Object)(object)<root>5__9 != (Object)null && !<>4__this._npcs.Contains((Component)(object)<root>5__9))
								{
									<>4__this._npcs.Add((Component)(object)<root>5__9);
								}
								<root>5__9 = null;
							}
							<go>5__8 = null;
						}
					}
					finally
					{
						if (<>s__7 != null)
						{
							<>s__7.Dispose();
						}
					}
					<>s__7 = null;
					<>s__10 = <>4__this._rigidbodies.GetEnumerator();
					try
					{
						while (<>s__10.MoveNext())
						{
							<rb>5__11 = <>s__10.Current;
							if (!((Object)(object)<rb>5__11 == (Object)null))
							{
								<rootName>5__12 = ((Object)<rb>5__11.transform.root).name;
								if (!IsPlayerOrRig(<rootName>5__12) && <rb>5__11.gameObject.layer != 0)
								{
									<>4__this._props.Add(<rb>5__11);
								}
								<rootName>5__12 = null;
								<rb>5__11 = null;
							}
						}
					}
					finally
					{
						((IDisposable)<>s__10).Dispose();
					}
					<>s__10 = default(List<Component>.Enumerator);
				}
				catch (Exception ex)
				{
					<ex>5__13 = ex;
					MelonLogger.Warning("[BoneFPS] Cache error: " + <ex>5__13.Message);
				}
				if (Log.Value)
				{
					MelonLogger.Msg($"[BoneFPS] Cached: R={<>4__this._renderers.Count} L={<>4__this._lights.Count} A={<>4__this._audio.Count} An={<>4__this._animators.Count} RB={<>4__this._rigidbodies.Count} PS={<>4__this._particles.Count} NPC={<>4__this._npcs.Count} Prop={<>4__this._props.Count} IK={<>4__this._ikSolvers.Count}");
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <SpawnAsync>d__274 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public string prefabPath;

		public Vector3 position;

		public Quaternion rotation;

		public Action<GameObject> callback;

		public BoneFpsMod <>4__this;

		private Type <spawnerType>5__1;

		private MethodInfo <spawnMethod>5__2;

		private Exception <ex>5__3;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <SpawnAsync>d__274(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<spawnerType>5__1 = null;
			<spawnMethod>5__2 = null;
			<ex>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				if (!AsyncSpawning.Value)
				{
					try
					{
						callback?.Invoke(null);
					}
					catch
					{
					}
					return false;
				}
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				try
				{
					<spawnerType>5__1 = Type.GetType("SLZ.Marrow.Pool.AssetSpawner, Assembly-CSharp");
					if (<spawnerType>5__1 != null)
					{
						<spawnMethod>5__2 = <spawnerType>5__1.GetMethod("Spawn", BindingFlags.Static | BindingFlags.Public);
						if (<spawnMethod>5__2 != null)
						{
						}
						<spawnMethod>5__2 = null;
					}
					callback?.Invoke(null);
					<spawnerType>5__1 = null;
				}
				catch (Exception ex)
				{
					<ex>5__3 = ex;
					if (Log.Value)
					{
						MelonLogger.Warning("[BoneFPS] Spawn error: " + <ex>5__3.Message);
					}
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static MelonPreferences_Category Cat;

	private static MelonPreferences_Category CatCulling;

	private static MelonPreferences_Category CatPhysics;

	private static MelonPreferences_Category CatSleep;

	private static MelonPreferences_Category CatFusion;

	private static MelonPreferences_Category CatSpawn;

	private static MelonPreferences_Category CatLoading;

	private static MelonPreferences_Category CatAdvanced;

	private static MelonPreferences_Category CatPlayer;

	private static MelonPreferences_Entry<bool> Enabled;

	private static MelonPreferences_Entry<bool> Log;

	private static MelonPreferences_Entry<bool> AggressiveMode;

	private static MelonPreferences_Entry<bool> UltraMode;

	private static MelonPreferences_Entry<bool> DisableVSync;

	private static MelonPreferences_Entry<int> MaxQueuedFrames;

	private static MelonPreferences_Entry<int> TargetFrameRate;

	private static MelonPreferences_Entry<float> XrRenderScale;

	private static MelonPreferences_Entry<int> TextureLimit;

	private static MelonPreferences_Entry<int> PixelLights;

	private static MelonPreferences_Entry<bool> DisableFog;

	private static MelonPreferences_Entry<bool> DisableHDR;

	private static MelonPreferences_Entry<bool> DisableMSAA;

	private static MelonPreferences_Entry<bool> DisableDepthTextures;

	private static MelonPreferences_Entry<bool> DisableShadows;

	private static MelonPreferences_Entry<float> ShadowDistance;

	private static MelonPreferences_Entry<bool> DisableReflectionProbes;

	private static MelonPreferences_Entry<bool> DisableRTTCameras;

	private static MelonPreferences_Entry<bool> GPUInstancing;

	private static MelonPreferences_Entry<bool> DrawCallBatching;

	private static MelonPreferences_Entry<bool> TextureStreaming;

	private static MelonPreferences_Entry<bool> MipmapStreaming;

	private static MelonPreferences_Entry<bool> OcclusionCullingEnhanced;

	private static MelonPreferences_Entry<bool> SmartCulling;

	private static MelonPreferences_Entry<float> CullInterval;

	private static MelonPreferences_Entry<bool> CullByFrustum;

	private static MelonPreferences_Entry<float> RendererMaxDistance;

	private static MelonPreferences_Entry<float> LightMaxDistance;

	private static MelonPreferences_Entry<float> AudioMaxDistance;

	private static MelonPreferences_Entry<float> AnimatorMaxDistance;

	private static MelonPreferences_Entry<float> ParticleMaxDistance;

	private static MelonPreferences_Entry<bool> HierarchicalCulling;

	private static MelonPreferences_Entry<bool> TemporalCoherenceCulling;

	private static MelonPreferences_Entry<bool> SoftwareOcclusion;

	private static MelonPreferences_Entry<int> OcclusionGridSize;

	private static MelonPreferences_Entry<bool> PortalCulling;

	private static MelonPreferences_Entry<bool> DynamicLOD;

	private static MelonPreferences_Entry<float> LODTier1Distance;

	private static MelonPreferences_Entry<float> LODTier2Distance;

	private static MelonPreferences_Entry<float> LODTier3Distance;

	private static MelonPreferences_Entry<float> LODTier4Distance;

	private static MelonPreferences_Entry<bool> AggressiveLOD;

	private static MelonPreferences_Entry<bool> PhysicsCulling;

	private static MelonPreferences_Entry<float> PhysicsCullDistance;

	private static MelonPreferences_Entry<float> PhysicsSleepThreshold;

	private static MelonPreferences_Entry<bool> AggressivePhysicsSleep;

	private static MelonPreferences_Entry<bool> BroadphaseOptimization;

	private static MelonPreferences_Entry<bool> ContactPairOptimization;

	private static MelonPreferences_Entry<bool> InterpolationOptimization;

	private static MelonPreferences_Entry<bool> PropSleep;

	private static MelonPreferences_Entry<float> PropSleepDistance;

	private static MelonPreferences_Entry<bool> NPCSleep;

	private static MelonPreferences_Entry<float> NPCSleepDistance;

	private static MelonPreferences_Entry<bool> AnimatorSleep;

	private static MelonPreferences_Entry<bool> RigidbodySleep;

	private static MelonPreferences_Entry<bool> ParticleSleep;

	private static MelonPreferences_Entry<bool> AudioSleep;

	private static MelonPreferences_Entry<bool> NavMeshAgentSleep;

	private static MelonPreferences_Entry<bool> ClothSleep;

	private static MelonPreferences_Entry<bool> TrailRendererSleep;

	private static MelonPreferences_Entry<bool> LineRendererSleep;

	private static MelonPreferences_Entry<bool> FusionOptimizations;

	private static MelonPreferences_Entry<float> FusionSyncDistance;

	private static MelonPreferences_Entry<bool> FusionReduceDistantUpdates;

	private static MelonPreferences_Entry<bool> FusionCullDistantPlayers;

	private static MelonPreferences_Entry<bool> FusionReducePhysicsSync;

	private static MelonPreferences_Entry<bool> FusionLODSync;

	private static MelonPreferences_Entry<bool> FusionVoiceDistanceCull;

	private static MelonPreferences_Entry<float> FusionVoiceMaxDistance;

	private static MelonPreferences_Entry<bool> FusionPropSyncOptimize;

	private static MelonPreferences_Entry<bool> FusionBandwidthThrottle;

	private static MelonPreferences_Entry<bool> FusionAvatarLOD;

	private static MelonPreferences_Entry<bool> FusionPacketBatching;

	private static MelonPreferences_Entry<bool> FusionDeltaCompression;

	private static MelonPreferences_Entry<bool> FusionPrioritySync;

	private static MelonPreferences_Entry<bool> FusionSpatialPartitioning;

	private static MelonPreferences_Entry<int> FusionTickRate;

	private static MelonPreferences_Entry<bool> FusionInterpolation;

	private static MelonPreferences_Entry<bool> FusionPrediction;

	private static MelonPreferences_Entry<bool> FusionVoiceCodecOptimize;

	private static MelonPreferences_Entry<bool> FusionCullInvisiblePlayers;

	private static MelonPreferences_Entry<bool> FusionReduceIK;

	private static MelonPreferences_Entry<bool> SpawnOptimization;

	private static MelonPreferences_Entry<bool> ObjectPooling;

	private static MelonPreferences_Entry<int> PoolSize;

	private static MelonPreferences_Entry<bool> AsyncSpawning;

	private static MelonPreferences_Entry<bool> DeferredInitialization;

	private static MelonPreferences_Entry<bool> SpawnQueueing;

	private static MelonPreferences_Entry<int> MaxSpawnsPerFrame;

	private static MelonPreferences_Entry<bool> PrewarmPools;

	private static MelonPreferences_Entry<bool> PrefabCaching;

	private static MelonPreferences_Entry<bool> InstantiateOptimize;

	private static MelonPreferences_Entry<bool> LoadingOptimization;

	private static MelonPreferences_Entry<bool> AssetBundleCaching;

	private static MelonPreferences_Entry<bool> BackgroundLoading;

	private static MelonPreferences_Entry<bool> StreamingOptimization;

	private static MelonPreferences_Entry<bool> MemoryMappedCaching;

	private static MelonPreferences_Entry<bool> PreloadAssets;

	private static MelonPreferences_Entry<bool> ShaderWarmup;

	private static MelonPreferences_Entry<bool> TexturePreload;

	private static MelonPreferences_Entry<bool> AudioPreload;

	private static MelonPreferences_Entry<int> LoadingThreadPriority;

	private static MelonPreferences_Entry<bool> ScenePreload;

	private static MelonPreferences_Entry<bool> IncrementalGC;

	private static MelonPreferences_Entry<bool> GCOptimization;

	private static MelonPreferences_Entry<bool> MemoryPooling;

	private static MelonPreferences_Entry<bool> StringPooling;

	private static MelonPreferences_Entry<bool> ListPooling;

	private static MelonPreferences_Entry<bool> ArrayPooling;

	private static MelonPreferences_Entry<bool> JobSystemUtilization;

	private static MelonPreferences_Entry<bool> MultiThreadedRendering;

	private static MelonPreferences_Entry<bool> GraphicsJobsMode;

	private static MelonPreferences_Entry<bool> AsyncGPUReadback;

	private static MelonPreferences_Entry<bool> CommandBufferOptimize;

	private static MelonPreferences_Entry<bool> MaterialPropertyBlockPool;

	private static MelonPreferences_Entry<bool> MeshCombining;

	private static MelonPreferences_Entry<bool> AudioCompression;

	private static MelonPreferences_Entry<bool> AnimationCompression;

	private static MelonPreferences_Entry<bool> VertexCompression;

	private static MelonPreferences_Entry<bool> IndexBufferOptimize;

	private static MelonPreferences_Entry<bool> PlayerOptimization;

	private static MelonPreferences_Entry<bool> LagCompensation;

	private static MelonPreferences_Entry<bool> DeltaTimeIndependentMovement;

	private static MelonPreferences_Entry<float> MinMovementSpeed;

	private static MelonPreferences_Entry<float> MaxDeltaTime;

	private static MelonPreferences_Entry<bool> IKOptimization;

	private static MelonPreferences_Entry<bool> HandTrackingOptimize;

	private static MelonPreferences_Entry<bool> AvatarLODOptimize;

	private static MelonPreferences_Entry<bool> PlayerPhysicsSimplify;

	private static MelonPreferences_Entry<bool> InputBuffering;

	private static MelonPreferences_Entry<bool> MovementPrediction;

	private static MelonPreferences_Entry<bool> SmoothMovement;

	private static MelonPreferences_Entry<float> MovementSmoothingFactor;

	private readonly List<Renderer> _renderers = new List<Renderer>(16384);

	private readonly List<Light> _lights = new List<Light>(2048);

	private readonly List<AudioSource> _audio = new List<AudioSource>(2048);

	private readonly List<Component> _animators = new List<Component>(2048);

	private readonly List<Camera> _cameras = new List<Camera>(128);

	private readonly List<Component> _rigidbodies = new List<Component>(8192);

	private readonly List<Component> _particles = new List<Component>(2048);

	private readonly List<Component> _reflectionProbes = new List<Component>(512);

	private readonly List<Component> _navMeshAgents = new List<Component>(512);

	private readonly List<Component> _npcs = new List<Component>(512);

	private readonly List<Component> _props = new List<Component>(4096);

	private readonly List<Component> _cloths = new List<Component>(256);

	private readonly List<Component> _trailRenderers = new List<Component>(512);

	private readonly List<Component> _lineRenderers = new List<Component>(512);

	private readonly List<Component> _lodGroups = new List<Component>(1024);

	private readonly List<Component> _colliders = new List<Component>(8192);

	private readonly List<Component> _joints = new List<Component>(1024);

	private readonly List<Component> _ikSolvers = new List<Component>(256);

	private readonly List<Component> _constraintComponents = new List<Component>(512);

	private readonly HashSet<int> _disabledRenderers = new HashSet<int>();

	private readonly HashSet<int> _disabledLights = new HashSet<int>();

	private readonly HashSet<int> _disabledAudio = new HashSet<int>();

	private readonly HashSet<int> _disabledAnimators = new HashSet<int>();

	private readonly HashSet<int> _disabledRTTCams = new HashSet<int>();

	private readonly HashSet<int> _sleepingRigidbodies = new HashSet<int>();

	private readonly HashSet<int> _sleepingParticles = new HashSet<int>();

	private readonly HashSet<int> _sleepingNPCs = new HashSet<int>();

	private readonly HashSet<int> _sleepingProps = new HashSet<int>();

	private readonly HashSet<int> _sleepingNavMeshAgents = new HashSet<int>();

	private readonly HashSet<int> _sleepingCloths = new HashSet<int>();

	private readonly HashSet<int> _sleepingTrails = new HashSet<int>();

	private readonly HashSet<int> _sleepingLines = new HashSet<int>();

	private readonly HashSet<int> _reducedShadowCasters = new HashSet<int>();

	private readonly HashSet<int> _culledAnimatorModes = new HashSet<int>();

	private readonly HashSet<int> _occludedObjects = new HashSet<int>();

	private readonly HashSet<int> _temporalCullCache = new HashSet<int>();

	private readonly HashSet<int> _processedThisFrame = new HashSet<int>();

	private readonly HashSet<int> _pooledObjects = new HashSet<int>();

	private readonly Dictionary<int, int> _originalShadowModes = new Dictionary<int, int>();

	private readonly Dictionary<int, int> _originalAnimatorModes = new Dictionary<int, int>();

	private readonly Dictionary<int, float> _originalRbSleepThresholds = new Dictionary<int, float>();

	private readonly Dictionary<int, Bounds> _cachedBounds = new Dictionary<int, Bounds>();

	private readonly Dictionary<int, float> _lastVisibleTime = new Dictionary<int, float>();

	private readonly Dictionary<int, int> _lodLevels = new Dictionary<int, int>();

	private readonly Dictionary<string, List<GameObject>> _objectPools = new Dictionary<string, List<GameObject>>();

	private readonly Dictionary<string, int> _poolUsageCount = new Dictionary<string, int>();

	private readonly bool[,] _occlusionGrid = new bool[64, 64];

	private readonly Dictionary<int, Vector2Int> _objectGridPositions = new Dictionary<int, Vector2Int>();

	private readonly List<Bounds> _occluderBounds = new List<Bounds>();

	private Vector3 _lastCamPos;

	private Quaternion _lastCamRot;

	private bool _cameraMovedSignificantly;

	private readonly Queue<SpawnRequest> _spawnQueue = new Queue<SpawnRequest>();

	private readonly List<GameObject> _warmPool = new List<GameObject>();

	private int _spawnsThisFrame;

	private float _accumulatedDeltaTime;

	private Vector3 _lastPlayerPosition;

	private Vector3 _playerVelocity;

	private float _averageFrameTime;

	private float _lagFactor = 1f;

	private readonly Queue<float> _frameTimeHistory = new Queue<float>();

	private const int FRAME_HISTORY_SIZE = 30;

	private readonly Plane[] _planes = (Plane[])(object)new Plane[6];

	private float _nextCullTime;

	private float _nextPhysicsTime;

	private float _nextSleepTime;

	private float _nextOcclusionTime;

	private float _nextPoolCleanupTime;

	private float _nextGCTime;

	private float _nextFusionOptTime;

	private float _nextPlayerOptTime;

	private float _nextDeepOptTime;

	private float _lastPlayerSearchTime;

	private bool _fusionLoaded;

	private Assembly _fusionAssembly;

	private bool _initialized;

	private object _playerRigManager;

	private Transform _playerHead;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("[BoneFPS] Loading v2.0.5 Ultimate Edition...");
		InitializePreferences();
		if (Enabled.Value)
		{
			ApplyGlobalTweaks();
			ApplyDeepOptimizations();
		}
		MelonCoroutines.Start(RebuildCachesDelayed());
		MelonCoroutines.Start(BackgroundOptimizationLoop());
		Hooking.OnLevelLoaded += OnLevelLoadedHook;
		SetupBoneMenu();
		CheckFusion();
		InitializeObjectPools();
		WarmupShaders();
		_initialized = true;
		MelonLogger.Msg("[BoneFPS] Loaded successfully with 50+ optimizations!");
	}

	private void InitializePreferences()
	{
		Cat = MelonPreferences.CreateCategory("BoneFPS_General");
		Enabled = Cat.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Log = Cat.CreateEntry<bool>("Log", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AggressiveMode = Cat.CreateEntry<bool>("AggressiveMode", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		UltraMode = Cat.CreateEntry<bool>("UltraMode", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableVSync = Cat.CreateEntry<bool>("DisableVSync", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MaxQueuedFrames = Cat.CreateEntry<int>("MaxQueuedFrames", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TargetFrameRate = Cat.CreateEntry<int>("TargetFrameRate", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		XrRenderScale = Cat.CreateEntry<float>("XrRenderScale", 0.85f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TextureLimit = Cat.CreateEntry<int>("TextureLimit", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PixelLights = Cat.CreateEntry<int>("PixelLights", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableFog = Cat.CreateEntry<bool>("DisableFog", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableHDR = Cat.CreateEntry<bool>("DisableHDR", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableMSAA = Cat.CreateEntry<bool>("DisableMSAA", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableDepthTextures = Cat.CreateEntry<bool>("DisableDepthTextures", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableShadows = Cat.CreateEntry<bool>("DisableShadows", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ShadowDistance = Cat.CreateEntry<float>("ShadowDistance", 30f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableReflectionProbes = Cat.CreateEntry<bool>("DisableReflectionProbes", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DisableRTTCameras = Cat.CreateEntry<bool>("DisableRTTCameras", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		GPUInstancing = Cat.CreateEntry<bool>("GPUInstancing", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DrawCallBatching = Cat.CreateEntry<bool>("DrawCallBatching", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TextureStreaming = Cat.CreateEntry<bool>("TextureStreaming", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MipmapStreaming = Cat.CreateEntry<bool>("MipmapStreaming", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		OcclusionCullingEnhanced = Cat.CreateEntry<bool>("OcclusionCullingEnhanced", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatCulling = MelonPreferences.CreateCategory("BoneFPS_Culling");
		SmartCulling = CatCulling.CreateEntry<bool>("SmartCulling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CullInterval = CatCulling.CreateEntry<float>("CullInterval", 0.1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CullByFrustum = CatCulling.CreateEntry<bool>("CullByFrustum", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		RendererMaxDistance = CatCulling.CreateEntry<float>("RendererMaxDistance", 100f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LightMaxDistance = CatCulling.CreateEntry<float>("LightMaxDistance", 50f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AudioMaxDistance = CatCulling.CreateEntry<float>("AudioMaxDistance", 60f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AnimatorMaxDistance = CatCulling.CreateEntry<float>("AnimatorMaxDistance", 80f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ParticleMaxDistance = CatCulling.CreateEntry<float>("ParticleMaxDistance", 60f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		HierarchicalCulling = CatCulling.CreateEntry<bool>("HierarchicalCulling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TemporalCoherenceCulling = CatCulling.CreateEntry<bool>("TemporalCoherenceCulling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		SoftwareOcclusion = CatCulling.CreateEntry<bool>("SoftwareOcclusion", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		OcclusionGridSize = CatCulling.CreateEntry<int>("OcclusionGridSize", 64, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PortalCulling = CatCulling.CreateEntry<bool>("PortalCulling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DynamicLOD = CatCulling.CreateEntry<bool>("DynamicLOD", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LODTier1Distance = CatCulling.CreateEntry<float>("LODTier1Distance", 15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LODTier2Distance = CatCulling.CreateEntry<float>("LODTier2Distance", 35f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LODTier3Distance = CatCulling.CreateEntry<float>("LODTier3Distance", 60f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LODTier4Distance = CatCulling.CreateEntry<float>("LODTier4Distance", 100f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AggressiveLOD = CatCulling.CreateEntry<bool>("AggressiveLOD", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatPhysics = MelonPreferences.CreateCategory("BoneFPS_Physics");
		PhysicsCulling = CatPhysics.CreateEntry<bool>("PhysicsCulling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PhysicsCullDistance = CatPhysics.CreateEntry<float>("PhysicsCullDistance", 50f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PhysicsSleepThreshold = CatPhysics.CreateEntry<float>("PhysicsSleepThreshold", 0.1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AggressivePhysicsSleep = CatPhysics.CreateEntry<bool>("AggressivePhysicsSleep", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		BroadphaseOptimization = CatPhysics.CreateEntry<bool>("BroadphaseOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ContactPairOptimization = CatPhysics.CreateEntry<bool>("ContactPairOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		InterpolationOptimization = CatPhysics.CreateEntry<bool>("InterpolationOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatSleep = MelonPreferences.CreateCategory("BoneFPS_Sleep");
		PropSleep = CatSleep.CreateEntry<bool>("PropSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PropSleepDistance = CatSleep.CreateEntry<float>("PropSleepDistance", 40f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		NPCSleep = CatSleep.CreateEntry<bool>("NPCSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		NPCSleepDistance = CatSleep.CreateEntry<float>("NPCSleepDistance", 60f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AnimatorSleep = CatSleep.CreateEntry<bool>("AnimatorSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		RigidbodySleep = CatSleep.CreateEntry<bool>("RigidbodySleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ParticleSleep = CatSleep.CreateEntry<bool>("ParticleSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AudioSleep = CatSleep.CreateEntry<bool>("AudioSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		NavMeshAgentSleep = CatSleep.CreateEntry<bool>("NavMeshAgentSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ClothSleep = CatSleep.CreateEntry<bool>("ClothSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TrailRendererSleep = CatSleep.CreateEntry<bool>("TrailRendererSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LineRendererSleep = CatSleep.CreateEntry<bool>("LineRendererSleep", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatFusion = MelonPreferences.CreateCategory("BoneFPS_Fusion");
		FusionOptimizations = CatFusion.CreateEntry<bool>("FusionOptimizations", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionSyncDistance = CatFusion.CreateEntry<float>("FusionSyncDistance", 100f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionReduceDistantUpdates = CatFusion.CreateEntry<bool>("FusionReduceDistantUpdates", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionCullDistantPlayers = CatFusion.CreateEntry<bool>("FusionCullDistantPlayers", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionReducePhysicsSync = CatFusion.CreateEntry<bool>("FusionReducePhysicsSync", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionLODSync = CatFusion.CreateEntry<bool>("FusionLODSync", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionVoiceDistanceCull = CatFusion.CreateEntry<bool>("FusionVoiceDistanceCull", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionVoiceMaxDistance = CatFusion.CreateEntry<float>("FusionVoiceMaxDistance", 50f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionPropSyncOptimize = CatFusion.CreateEntry<bool>("FusionPropSyncOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionBandwidthThrottle = CatFusion.CreateEntry<bool>("FusionBandwidthThrottle", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionAvatarLOD = CatFusion.CreateEntry<bool>("FusionAvatarLOD", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionPacketBatching = CatFusion.CreateEntry<bool>("FusionPacketBatching", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionDeltaCompression = CatFusion.CreateEntry<bool>("FusionDeltaCompression", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionPrioritySync = CatFusion.CreateEntry<bool>("FusionPrioritySync", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionSpatialPartitioning = CatFusion.CreateEntry<bool>("FusionSpatialPartitioning", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionTickRate = CatFusion.CreateEntry<int>("FusionTickRate", 30, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionInterpolation = CatFusion.CreateEntry<bool>("FusionInterpolation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionPrediction = CatFusion.CreateEntry<bool>("FusionPrediction", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionVoiceCodecOptimize = CatFusion.CreateEntry<bool>("FusionVoiceCodecOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionCullInvisiblePlayers = CatFusion.CreateEntry<bool>("FusionCullInvisiblePlayers", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		FusionReduceIK = CatFusion.CreateEntry<bool>("FusionReduceIK", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatSpawn = MelonPreferences.CreateCategory("BoneFPS_Spawn");
		SpawnOptimization = CatSpawn.CreateEntry<bool>("SpawnOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ObjectPooling = CatSpawn.CreateEntry<bool>("ObjectPooling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PoolSize = CatSpawn.CreateEntry<int>("PoolSize", 50, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AsyncSpawning = CatSpawn.CreateEntry<bool>("AsyncSpawning", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DeferredInitialization = CatSpawn.CreateEntry<bool>("DeferredInitialization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		SpawnQueueing = CatSpawn.CreateEntry<bool>("SpawnQueueing", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MaxSpawnsPerFrame = CatSpawn.CreateEntry<int>("MaxSpawnsPerFrame", 3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PrewarmPools = CatSpawn.CreateEntry<bool>("PrewarmPools", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PrefabCaching = CatSpawn.CreateEntry<bool>("PrefabCaching", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		InstantiateOptimize = CatSpawn.CreateEntry<bool>("InstantiateOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatLoading = MelonPreferences.CreateCategory("BoneFPS_Loading");
		LoadingOptimization = CatLoading.CreateEntry<bool>("LoadingOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AssetBundleCaching = CatLoading.CreateEntry<bool>("AssetBundleCaching", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		BackgroundLoading = CatLoading.CreateEntry<bool>("BackgroundLoading", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		StreamingOptimization = CatLoading.CreateEntry<bool>("StreamingOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MemoryMappedCaching = CatLoading.CreateEntry<bool>("MemoryMappedCaching", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PreloadAssets = CatLoading.CreateEntry<bool>("PreloadAssets", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ShaderWarmup = CatLoading.CreateEntry<bool>("ShaderWarmup", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		TexturePreload = CatLoading.CreateEntry<bool>("TexturePreload", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AudioPreload = CatLoading.CreateEntry<bool>("AudioPreload", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LoadingThreadPriority = CatLoading.CreateEntry<int>("LoadingThreadPriority", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ScenePreload = CatLoading.CreateEntry<bool>("ScenePreload", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IncrementalGC = CatLoading.CreateEntry<bool>("IncrementalGC", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatAdvanced = MelonPreferences.CreateCategory("BoneFPS_Advanced");
		GCOptimization = CatAdvanced.CreateEntry<bool>("GCOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MemoryPooling = CatAdvanced.CreateEntry<bool>("MemoryPooling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		StringPooling = CatAdvanced.CreateEntry<bool>("StringPooling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ListPooling = CatAdvanced.CreateEntry<bool>("ListPooling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		ArrayPooling = CatAdvanced.CreateEntry<bool>("ArrayPooling", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		JobSystemUtilization = CatAdvanced.CreateEntry<bool>("JobSystemUtilization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MultiThreadedRendering = CatAdvanced.CreateEntry<bool>("MultiThreadedRendering", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		GraphicsJobsMode = CatAdvanced.CreateEntry<bool>("GraphicsJobsMode", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AsyncGPUReadback = CatAdvanced.CreateEntry<bool>("AsyncGPUReadback", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CommandBufferOptimize = CatAdvanced.CreateEntry<bool>("CommandBufferOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MaterialPropertyBlockPool = CatAdvanced.CreateEntry<bool>("MaterialPropertyBlockPool", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MeshCombining = CatAdvanced.CreateEntry<bool>("MeshCombining", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AudioCompression = CatAdvanced.CreateEntry<bool>("AudioCompression", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AnimationCompression = CatAdvanced.CreateEntry<bool>("AnimationCompression", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		VertexCompression = CatAdvanced.CreateEntry<bool>("VertexCompression", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IndexBufferOptimize = CatAdvanced.CreateEntry<bool>("IndexBufferOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CatPlayer = MelonPreferences.CreateCategory("BoneFPS_Player");
		PlayerOptimization = CatPlayer.CreateEntry<bool>("PlayerOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		LagCompensation = CatPlayer.CreateEntry<bool>("LagCompensation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		DeltaTimeIndependentMovement = CatPlayer.CreateEntry<bool>("DeltaTimeIndependentMovement", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MinMovementSpeed = CatPlayer.CreateEntry<float>("MinMovementSpeed", 0.8f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MaxDeltaTime = CatPlayer.CreateEntry<float>("MaxDeltaTime", 0.1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IKOptimization = CatPlayer.CreateEntry<bool>("IKOptimization", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		HandTrackingOptimize = CatPlayer.CreateEntry<bool>("HandTrackingOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AvatarLODOptimize = CatPlayer.CreateEntry<bool>("AvatarLODOptimize", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		PlayerPhysicsSimplify = CatPlayer.CreateEntry<bool>("PlayerPhysicsSimplify", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		InputBuffering = CatPlayer.CreateEntry<bool>("InputBuffering", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MovementPrediction = CatPlayer.CreateEntry<bool>("MovementPrediction", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		SmoothMovement = CatPlayer.CreateEntry<bool>("SmoothMovement", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MovementSmoothingFactor = CatPlayer.CreateEntry<float>("MovementSmoothingFactor", 0.15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
	}

	private void CheckFusion()
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			if (assembly.GetName().Name.Equals("LabFusion", StringComparison.OrdinalIgnoreCase))
			{
				_fusionLoaded = true;
				_fusionAssembly = assembly;
				MelonLogger.Msg("[BoneFPS] LabFusion detected - enabling multiplayer optimizations!");
				break;
			}
		}
	}

	private void OnLevelLoadedHook(LevelInfo info)
	{
		if (Enabled.Value)
		{
			ApplyGlobalTweaks();
			ApplyDeepOptimizations();
			MelonCoroutines.Start(RebuildCachesDelayed());
			MelonCoroutines.Start(PreloadLevelAssets());
			ClearTemporalCache();
			ResetOcclusionGrid();
			_playerRigManager = null;
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (Enabled.Value)
		{
			ApplyGlobalTweaks();
			ApplyDeepOptimizations();
			MelonCoroutines.Start(RebuildCachesDelayed());
			MelonCoroutines.Start(PreloadLevelAssets());
			_playerRigManager = null;
		}
	}

	public override void OnUpdate()
	{
		if (!Enabled.Value || !_initialized)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		float unscaledDeltaTime = Time.unscaledDeltaTime;
		UpdateFrameTimeHistory(unscaledDeltaTime);
		Camera bestCamera = GetBestCamera();
		if (!((Object)(object)bestCamera == (Object)null))
		{
			if (_playerRigManager == null && unscaledTime - _lastPlayerSearchTime > 2f)
			{
				FindPlayerReferences();
				_lastPlayerSearchTime = unscaledTime;
			}
			if (DeltaTimeIndependentMovement.Value && LagCompensation.Value)
			{
				ApplyLagCompensation(unscaledDeltaTime);
			}
			ApplyPerCameraTweaks(bestCamera);
			CheckCameraMovement(bestCamera);
			if (SmartCulling.Value && unscaledTime >= _nextCullTime)
			{
				_nextCullTime = unscaledTime + Mathf.Max(0.03f, CullInterval.Value);
				DoSmartCulling(bestCamera);
			}
			if (OcclusionCullingEnhanced.Value && unscaledTime >= _nextOcclusionTime)
			{
				_nextOcclusionTime = unscaledTime + 0.1f;
				DoEnhancedOcclusionCulling(bestCamera);
			}
			if (PhysicsCulling.Value && unscaledTime >= _nextPhysicsTime)
			{
				_nextPhysicsTime = unscaledTime + 0.15f;
				DoPhysicsCulling(bestCamera);
			}
			if (unscaledTime >= _nextSleepTime)
			{
				_nextSleepTime = unscaledTime + 0.25f;
				DoSleepSystems(bestCamera);
			}
			if (_fusionLoaded && FusionOptimizations.Value && unscaledTime >= _nextFusionOptTime)
			{
				_nextFusionOptTime = unscaledTime + 0.1f;
				DoFusionOptimizations(bestCamera);
			}
			if (PlayerOptimization.Value && unscaledTime >= _nextPlayerOptTime)
			{
				_nextPlayerOptTime = unscaledTime + 0.05f;
				DoPlayerOptimizations(bestCamera);
			}
			if (unscaledTime >= _nextDeepOptTime)
			{
				_nextDeepOptTime = unscaledTime + 0.5f;
				DoDeepOptimizations();
			}
			if (SpawnQueueing.Value)
			{
				ProcessSpawnQueue();
			}
			if (ObjectPooling.Value && unscaledTime >= _nextPoolCleanupTime)
			{
				_nextPoolCleanupTime = unscaledTime + 30f;
				CleanupObjectPools();
			}
			if (GCOptimization.Value && unscaledTime >= _nextGCTime)
			{
				_nextGCTime = unscaledTime + 60f;
				DoGCOptimization();
			}
			_processedThisFrame.Clear();
			_spawnsThisFrame = 0;
		}
	}

	public override void OnFixedUpdate()
	{
		if (Enabled.Value && (AggressiveMode.Value || UltraMode.Value))
		{
			OptimizePhysicsStep();
		}
	}

	private void ApplyGlobalTweaks()
	{
		if (DisableVSync.Value)
		{
			QualitySettings.vSyncCount = 0;
		}
		TrySetStaticProperty(typeof(QualitySettings), "maxQueuedFrames", Mathf.Clamp(MaxQueuedFrames.Value, 0, 3));
		try
		{
			Application.targetFrameRate = TargetFrameRate.Value;
		}
		catch
		{
		}
		TrySetXrRenderScale(Mathf.Clamp(XrRenderScale.Value, 0.5f, 1.2f));
		QualitySettings.masterTextureLimit = Mathf.Clamp(TextureLimit.Value, 0, 3);
		QualitySettings.pixelLightCount = Mathf.Clamp(PixelLights.Value, 0, 8);
		if (DisableFog.Value)
		{
			RenderSettings.fog = false;
		}
		if (DisableShadows.Value)
		{
			QualitySettings.shadows = (ShadowQuality)0;
		}
		else
		{
			QualitySettings.shadowDistance = Mathf.Clamp(ShadowDistance.Value, 5f, 150f);
		}
		if (DisableReflectionProbes.Value)
		{
			QualitySettings.realtimeReflectionProbes = false;
		}
		float lodBias = (UltraMode.Value ? 0.3f : (AggressiveMode.Value ? 0.5f : 0.8f));
		QualitySettings.lodBias = lodBias;
		QualitySettings.maximumLODLevel = (UltraMode.Value ? 2 : (AggressiveMode.Value ? 1 : 0));
		QualitySettings.skinWeights = (SkinWeights)(UltraMode.Value ? 1 : (AggressiveMode.Value ? 2 : 4));
		QualitySettings.anisotropicFiltering = (AnisotropicFiltering)((!AggressiveMode.Value && !UltraMode.Value) ? 1 : 0);
		if (TextureStreaming.Value)
		{
			TrySetStaticProperty(typeof(QualitySettings), "streamingMipmapsActive", true);
			TrySetStaticProperty(typeof(QualitySettings), "streamingMipmapsMemoryBudget", 256f);
			TrySetStaticProperty(typeof(QualitySettings), "streamingMipmapsMaxLevelReduction", 2);
		}
		if (PhysicsCulling.Value)
		{
			float fixedDeltaTime = (UltraMode.Value ? 0.025f : (AggressiveMode.Value ? 0.02f : 0.0167f));
			Time.fixedDeltaTime = fixedDeltaTime;
			TrySetStaticProperty(typeof(Physics), "autoSyncTransforms", false);
			TrySetStaticProperty(typeof(Physics), "autoSimulation", true);
			int num = (UltraMode.Value ? 2 : (AggressiveMode.Value ? 4 : 6));
			TrySetStaticProperty(typeof(Physics), "defaultSolverIterations", num);
			TrySetStaticProperty(typeof(Physics), "defaultSolverVelocityIterations", 1);
			TrySetStaticProperty(typeof(Physics), "sleepThreshold", Mathf.Max(0.005f, PhysicsSleepThreshold.Value));
			if (BroadphaseOptimization.Value)
			{
				TrySetStaticProperty(typeof(Physics), "defaultContactOffset", 0.02f);
				TrySetStaticProperty(typeof(Physics), "bounceThreshold", 2f);
			}
		}
		TrySetStaticProperty(typeof(QualitySettings), "asyncUploadTimeSlice", 2);
		TrySetStaticProperty(typeof(QualitySettings), "asyncUploadBufferSize", 16);
		TrySetStaticProperty(typeof(QualitySettings), "asyncUploadPersistentBuffer", true);
		if (GPUInstancing.Value)
		{
			EnableGPUInstancing();
		}
		if (BackgroundLoading.Value)
		{
			Application.backgroundLoadingPriority = (ThreadPriority)Mathf.Clamp(LoadingThreadPriority.Value, 0, 4);
		}
		if (IncrementalGC.Value)
		{
			try
			{
				Type typeFromHandle = typeof(GarbageCollector);
				PropertyInfo property = typeFromHandle.GetProperty("GCMode");
				if (property != null)
				{
					object value = Enum.ToObject(property.PropertyType, 1);
					property.SetValue(null, value);
				}
			}
			catch
			{
			}
		}
		if (Log.Value)
		{
			MelonLogger.Msg("[BoneFPS] Applied global tweaks.");
		}
	}

	private void ApplyPerCameraTweaks(Camera cam)
	{
		if (DisableHDR.Value)
		{
			cam.allowHDR = false;
		}
		if (DisableMSAA.Value)
		{
			cam.allowMSAA = false;
		}
		if (DisableDepthTextures.Value)
		{
			try
			{
				cam.depthTextureMode = (DepthTextureMode)0;
			}
			catch
			{
			}
		}
		cam.useOcclusionCulling = true;
		if (UltraMode.Value)
		{
			cam.farClipPlane = Mathf.Min(cam.farClipPlane, 500f);
		}
	}

	private void ApplyDeepOptimizations()
	{
		if (ShaderWarmup.Value)
		{
			WarmupShaders();
		}
		if (AudioCompression.Value)
		{
			OptimizeAudioSettings();
		}
		if (AnimationCompression.Value)
		{
			OptimizeAnimations();
		}
	}

	private void DoDeepOptimizations()
	{
		if (VertexCompression.Value)
		{
			OptimizeVertexBuffers();
		}
		if (UltraMode.Value)
		{
			Resources.UnloadUnusedAssets();
		}
	}

	private void WarmupShaders()
	{
		try
		{
			Type type = Type.GetType("UnityEngine.Rendering.ShaderWarmup, UnityEngine.CoreModule");
			if (type != null)
			{
				type.GetMethod("WarmupAllShaders", BindingFlags.Static | BindingFlags.Public)?.Invoke(null, null);
			}
			Shader.WarmupAllShaders();
		}
		catch (Exception ex)
		{
			if (Log.Value)
			{
				MelonLogger.Warning("[BoneFPS] Shader warmup failed: " + ex.Message);
			}
		}
	}

	private void OptimizeAudioSettings()
	{
		try
		{
			foreach (AudioSource item in _audio)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				AudioSource val = item;
				if (!((Object)(object)val == (Object)null))
				{
					val.priority = 128;
					if (!val.isPlaying)
					{
						val.spatialize = false;
					}
				}
			}
		}
		catch
		{
		}
	}

	private void OptimizeAnimations()
	{
		foreach (Component animator in _animators)
		{
			if (!((Object)(object)animator == (Object)null))
			{
				try
				{
					TrySetProperty(animator, "keepAnimatorControllerStateOnDisable", true);
					TrySetProperty(animator, "fireEvents", false);
					TrySetProperty(animator, "logWarnings", false);
				}
				catch
				{
				}
			}
		}
	}

	private void OptimizeVertexBuffers()
	{
		foreach (Renderer renderer in _renderers)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				continue;
			}
			MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
			{
				try
				{
					component.sharedMesh.MarkDynamic();
				}
				catch
				{
				}
			}
		}
	}

	private void EnableGPUInstancing()
	{
		foreach (Renderer renderer in _renderers)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				continue;
			}
			Il2CppReferenceArray<Material> sharedMaterials = renderer.sharedMaterials;
			foreach (Material item in (Il2CppArrayBase<Material>)(object)sharedMaterials)
			{
				if (!((Object)(object)item != (Object)null) || !((Object)(object)item.shader != (Object)null))
				{
					continue;
				}
				try
				{
					if (((Object)item.shader).name.Contains("Standard") || item.enableInstancing)
					{
						item.enableInstancing = true;
					}
				}
				catch
				{
				}
			}
		}
	}

	private void OptimizePhysicsStep()
	{
		if (_averageFrameTime > 0.02f)
		{
			Time.fixedDeltaTime = Mathf.Min(0.03f, Time.fixedDeltaTime * 1.1f);
		}
		else if (_averageFrameTime < 0.012f)
		{
			Time.fixedDeltaTime = Mathf.Max(0.0167f, Time.fixedDeltaTime * 0.95f);
		}
	}

	private void DoSmartCulling(Camera cam)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_0555: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0560: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a10: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a15: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a16: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a1b: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Invalid comparison between Unknown and I4
		//IL_0b13: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b18: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b19: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b1e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c16: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c1b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c1c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c21: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)cam).transform.position;
		bool value = CullByFrustum.Value;
		bool value2 = HierarchicalCulling.Value;
		bool value3 = TemporalCoherenceCulling.Value;
		if (value)
		{
			GeometryUtility.CalculateFrustumPlanes(cam, Il2CppStructArray<Plane>.op_Implicit(_planes));
		}
		float num = RendererMaxDistance.Value * RendererMaxDistance.Value;
		float num2 = LightMaxDistance.Value * LightMaxDistance.Value;
		float num3 = AudioMaxDistance.Value * AudioMaxDistance.Value;
		float num4 = AnimatorMaxDistance.Value * AnimatorMaxDistance.Value;
		float num5 = ParticleMaxDistance.Value * ParticleMaxDistance.Value;
		float num6 = LODTier1Distance.Value * LODTier1Distance.Value;
		float num7 = LODTier2Distance.Value * LODTier2Distance.Value;
		float num8 = LODTier3Distance.Value * LODTier3Distance.Value;
		float lod4Sq = LODTier4Distance.Value * LODTier4Distance.Value;
		float unscaledTime = Time.unscaledTime;
		Vector3 val2;
		for (int i = 0; i < _renderers.Count; i++)
		{
			Renderer val = _renderers[i];
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy || IsPlayerOrRig(((Object)((Component)val).transform.root).name))
			{
				continue;
			}
			int instanceID = ((Object)val).GetInstanceID();
			if (value3 && !_cameraMovedSignificantly && _temporalCullCache.Contains(instanceID))
			{
				continue;
			}
			if (!_cachedBounds.TryGetValue(instanceID, out var value4))
			{
				try
				{
					value4 = val.bounds;
					_cachedBounds[instanceID] = value4;
				}
				catch
				{
					continue;
				}
			}
			else if (Time.frameCount % 10 == instanceID % 10)
			{
				try
				{
					value4 = val.bounds;
					_cachedBounds[instanceID] = value4;
				}
				catch
				{
				}
			}
			val2 = ((Bounds)(ref value4)).center - position;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			bool flag = sqrMagnitude <= num;
			bool flag2 = !value || GeometryUtility.TestPlanesAABB(Il2CppStructArray<Plane>.op_Implicit(_planes), value4);
			bool flag3 = flag && flag2;
			if (flag3 && SoftwareOcclusion.Value)
			{
				flag3 = !IsOccluded(instanceID, value4, position);
			}
			if (!flag3 && val.enabled)
			{
				val.enabled = false;
				_disabledRenderers.Add(instanceID);
				_temporalCullCache.Add(instanceID);
			}
			else if (flag3 && !val.enabled && _disabledRenderers.Contains(instanceID))
			{
				val.enabled = true;
				_disabledRenderers.Remove(instanceID);
				_lastVisibleTime[instanceID] = unscaledTime;
				_temporalCullCache.Remove(instanceID);
			}
			if (DynamicLOD.Value && val.enabled)
			{
				ApplyDynamicLOD4Tier(val, sqrMagnitude, num6, num7, num8, lod4Sq);
			}
		}
		for (int j = 0; j < _lights.Count; j++)
		{
			Light val3 = _lights[j];
			if ((Object)(object)val3 == (Object)null || !((Component)val3).gameObject.activeInHierarchy)
			{
				continue;
			}
			val2 = ((Component)val3).transform.position - position;
			float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
			bool flag4 = sqrMagnitude2 <= num2;
			int instanceID2 = ((Object)val3).GetInstanceID();
			if (!flag4 && ((Behaviour)val3).enabled)
			{
				((Behaviour)val3).enabled = false;
				_disabledLights.Add(instanceID2);
			}
			else if (flag4 && !((Behaviour)val3).enabled && _disabledLights.Contains(instanceID2))
			{
				((Behaviour)val3).enabled = true;
				_disabledLights.Remove(instanceID2);
			}
			if (DynamicLOD.Value && ((Behaviour)val3).enabled && (int)val3.shadows > 0)
			{
				if (sqrMagnitude2 > num8)
				{
					val3.shadows = (LightShadows)0;
					val3.renderMode = (LightRenderMode)2;
				}
				else if (sqrMagnitude2 > num7)
				{
					val3.shadows = (LightShadows)1;
					val3.renderMode = (LightRenderMode)1;
				}
				else if (sqrMagnitude2 > num6)
				{
					val3.shadows = (LightShadows)1;
				}
			}
		}
		if (AudioSleep.Value)
		{
			for (int k = 0; k < _audio.Count; k++)
			{
				AudioSource val4 = _audio[k];
				if (!((Object)(object)val4 == (Object)null) && ((Component)val4).gameObject.activeInHierarchy)
				{
					val2 = ((Component)val4).transform.position - position;
					float sqrMagnitude3 = ((Vector3)(ref val2)).sqrMagnitude;
					bool flag5 = sqrMagnitude3 <= num3;
					int instanceID3 = ((Object)val4).GetInstanceID();
					if (!flag5 && ((Behaviour)val4).enabled)
					{
						((Behaviour)val4).enabled = false;
						_disabledAudio.Add(instanceID3);
					}
					else if (flag5 && !((Behaviour)val4).enabled && _disabledAudio.Contains(instanceID3))
					{
						((Behaviour)val4).enabled = true;
						_disabledAudio.Remove(instanceID3);
					}
					if (((Behaviour)val4).enabled && sqrMagnitude3 > num7)
					{
						float num9 = 1f - Mathf.Clamp01((Mathf.Sqrt(sqrMagnitude3) - LODTier2Distance.Value) / (AudioMaxDistance.Value - LODTier2Distance.Value));
						val4.volume = Mathf.Min(val4.volume, num9);
					}
				}
			}
		}
		if (AnimatorSleep.Value)
		{
			for (int l = 0; l < _animators.Count; l++)
			{
				Component val5 = _animators[l];
				if ((Object)(object)val5 == (Object)null || !val5.gameObject.activeInHierarchy || IsPlayerOrRig(((Object)val5.transform.root).name))
				{
					continue;
				}
				val2 = val5.transform.position - position;
				float sqrMagnitude4 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID4 = ((Object)val5).GetInstanceID();
				Behaviour val6 = (Behaviour)(object)((val5 is Behaviour) ? val5 : null);
				if ((Object)(object)val6 == (Object)null)
				{
					continue;
				}
				if (sqrMagnitude4 > num4)
				{
					if (val6.enabled)
					{
						val6.enabled = false;
						_disabledAnimators.Add(instanceID4);
					}
					continue;
				}
				if (sqrMagnitude4 > num8)
				{
					if (!_culledAnimatorModes.Contains(instanceID4))
					{
						SaveAnimatorCullingMode(val5, instanceID4);
						SetAnimatorCullingMode(val5, 2);
						SetAnimatorUpdateMode(val5, 0);
						_culledAnimatorModes.Add(instanceID4);
					}
					continue;
				}
				if (sqrMagnitude4 > num7)
				{
					if (!_culledAnimatorModes.Contains(instanceID4))
					{
						SaveAnimatorCullingMode(val5, instanceID4);
						SetAnimatorCullingMode(val5, 1);
						_culledAnimatorModes.Add(instanceID4);
					}
					continue;
				}
				if (!val6.enabled && _disabledAnimators.Contains(instanceID4))
				{
					val6.enabled = true;
					_disabledAnimators.Remove(instanceID4);
				}
				if (_culledAnimatorModes.Contains(instanceID4))
				{
					RestoreAnimatorCullingMode(val5, instanceID4);
					_culledAnimatorModes.Remove(instanceID4);
				}
			}
		}
		if (ParticleSleep.Value)
		{
			for (int m = 0; m < _particles.Count; m++)
			{
				Component val7 = _particles[m];
				if ((Object)(object)val7 == (Object)null || !val7.gameObject.activeInHierarchy)
				{
					continue;
				}
				val2 = val7.transform.position - position;
				float sqrMagnitude5 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID5 = ((Object)val7).GetInstanceID();
				bool particleIsPlaying = GetParticleIsPlaying(val7);
				if (sqrMagnitude5 > num5)
				{
					if (particleIsPlaying)
					{
						StopParticle(val7);
						_sleepingParticles.Add(instanceID5);
					}
					continue;
				}
				if (!particleIsPlaying && _sleepingParticles.Contains(instanceID5))
				{
					PlayParticle(val7);
					_sleepingParticles.Remove(instanceID5);
				}
				if (sqrMagnitude5 > num7)
				{
					ReduceParticleEmission(val7, 0.5f);
				}
			}
		}
		if (TrailRendererSleep.Value)
		{
			for (int n = 0; n < _trailRenderers.Count; n++)
			{
				Component val8 = _trailRenderers[n];
				if ((Object)(object)val8 == (Object)null)
				{
					continue;
				}
				Behaviour val9 = (Behaviour)(object)((val8 is Behaviour) ? val8 : null);
				if ((Object)(object)val9 == (Object)null)
				{
					continue;
				}
				val2 = val8.transform.position - position;
				float sqrMagnitude6 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID6 = ((Object)val8).GetInstanceID();
				if (sqrMagnitude6 > num8)
				{
					if (val9.enabled)
					{
						val9.enabled = false;
						_sleepingTrails.Add(instanceID6);
					}
				}
				else if (_sleepingTrails.Contains(instanceID6))
				{
					val9.enabled = true;
					_sleepingTrails.Remove(instanceID6);
				}
			}
		}
		if (LineRendererSleep.Value)
		{
			for (int num10 = 0; num10 < _lineRenderers.Count; num10++)
			{
				Component val10 = _lineRenderers[num10];
				if ((Object)(object)val10 == (Object)null)
				{
					continue;
				}
				Behaviour val11 = (Behaviour)(object)((val10 is Behaviour) ? val10 : null);
				if ((Object)(object)val11 == (Object)null)
				{
					continue;
				}
				val2 = val10.transform.position - position;
				float sqrMagnitude7 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID7 = ((Object)val10).GetInstanceID();
				if (sqrMagnitude7 > num8)
				{
					if (val11.enabled)
					{
						val11.enabled = false;
						_sleepingLines.Add(instanceID7);
					}
				}
				else if (_sleepingLines.Contains(instanceID7))
				{
					val11.enabled = true;
					_sleepingLines.Remove(instanceID7);
				}
			}
		}
		if (ClothSleep.Value)
		{
			for (int num11 = 0; num11 < _cloths.Count; num11++)
			{
				Component val12 = _cloths[num11];
				if ((Object)(object)val12 == (Object)null)
				{
					continue;
				}
				Behaviour val13 = (Behaviour)(object)((val12 is Behaviour) ? val12 : null);
				if ((Object)(object)val13 == (Object)null)
				{
					continue;
				}
				val2 = val12.transform.position - position;
				float sqrMagnitude8 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID8 = ((Object)val12).GetInstanceID();
				if (sqrMagnitude8 > num7)
				{
					if (val13.enabled)
					{
						val13.enabled = false;
						_sleepingCloths.Add(instanceID8);
					}
				}
				else if (_sleepingCloths.Contains(instanceID8))
				{
					val13.enabled = true;
					_sleepingCloths.Remove(instanceID8);
				}
			}
		}
		if (!DisableRTTCameras.Value)
		{
			return;
		}
		for (int num12 = 0; num12 < _cameras.Count; num12++)
		{
			Camera val14 = _cameras[num12];
			if (!((Object)(object)val14 == (Object)null) && ((Component)val14).gameObject.activeInHierarchy && !((Object)(object)val14 == (Object)(object)cam))
			{
				int instanceID9 = ((Object)val14).GetInstanceID();
				bool flag6 = (Object)(object)val14.targetTexture != (Object)null;
				if (flag6 && ((Behaviour)val14).enabled)
				{
					((Behaviour)val14).enabled = false;
					_disabledRTTCams.Add(instanceID9);
				}
				else if (!flag6 && !((Behaviour)val14).enabled && _disabledRTTCams.Contains(instanceID9))
				{
					((Behaviour)val14).enabled = true;
					_disabledRTTCams.Remove(instanceID9);
				}
			}
		}
	}

	private void ApplyDynamicLOD4Tier(Renderer r, float distSq, float lod1Sq, float lod2Sq, float lod3Sq, float lod4Sq)
	{
		int instanceID = ((Object)r).GetInstanceID();
		if (distSq > lod4Sq)
		{
			SetShadowCastingMode(r, 0);
			r.receiveShadows = false;
			r.allowOcclusionWhenDynamic = false;
			SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
			if (val != null)
			{
				val.updateWhenOffscreen = false;
				val.quality = (SkinQuality)1;
				TrySetProperty(val, "skinnedMotionVectors", false);
			}
			if (!_reducedShadowCasters.Contains(instanceID))
			{
				if (!_originalShadowModes.ContainsKey(instanceID))
				{
					_originalShadowModes[instanceID] = GetShadowCastingMode(r);
				}
				_reducedShadowCasters.Add(instanceID);
			}
			return;
		}
		if (distSq > lod3Sq)
		{
			SetShadowCastingMode(r, 0);
			r.receiveShadows = false;
			SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
			if (val2 != null)
			{
				val2.updateWhenOffscreen = false;
				val2.quality = (SkinQuality)2;
				TrySetProperty(val2, "skinnedMotionVectors", false);
			}
			if (!_reducedShadowCasters.Contains(instanceID))
			{
				if (!_originalShadowModes.ContainsKey(instanceID))
				{
					_originalShadowModes[instanceID] = GetShadowCastingMode(r);
				}
				_reducedShadowCasters.Add(instanceID);
			}
			return;
		}
		if (distSq > lod2Sq)
		{
			int shadowCastingMode = GetShadowCastingMode(r);
			if (shadowCastingMode != 0)
			{
				if (!_originalShadowModes.ContainsKey(instanceID))
				{
					_originalShadowModes[instanceID] = shadowCastingMode;
				}
				SetShadowCastingMode(r, 0);
				_reducedShadowCasters.Add(instanceID);
			}
			r.receiveShadows = false;
			SkinnedMeshRenderer val3 = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
			if (val3 != null)
			{
				val3.updateWhenOffscreen = false;
				val3.quality = (SkinQuality)2;
			}
			return;
		}
		if (distSq > lod1Sq)
		{
			int shadowCastingMode2 = GetShadowCastingMode(r);
			if (shadowCastingMode2 == 1)
			{
				if (!_originalShadowModes.ContainsKey(instanceID))
				{
					_originalShadowModes[instanceID] = shadowCastingMode2;
				}
				SetShadowCastingMode(r, 2);
				_reducedShadowCasters.Add(instanceID);
			}
			SkinnedMeshRenderer val4 = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
			if (val4 != null)
			{
				val4.quality = (SkinQuality)4;
			}
			return;
		}
		if (_reducedShadowCasters.Contains(instanceID))
		{
			if (_originalShadowModes.TryGetValue(instanceID, out var value))
			{
				SetShadowCastingMode(r, value);
			}
			r.receiveShadows = true;
			r.allowOcclusionWhenDynamic = true;
			_reducedShadowCasters.Remove(instanceID);
		}
		SkinnedMeshRenderer val5 = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
		if (val5 != null)
		{
			val5.quality = (SkinQuality)0;
			TrySetProperty(val5, "skinnedMotionVectors", true);
		}
	}

	private void DoEnhancedOcclusionCulling(Camera cam)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		if (!SoftwareOcclusion.Value)
		{
			return;
		}
		Vector3 position = ((Component)cam).transform.position;
		_occluderBounds.Clear();
		foreach (Renderer renderer in _renderers)
		{
			if (!((Object)(object)renderer == (Object)null) && renderer.enabled && _cachedBounds.TryGetValue(((Object)renderer).GetInstanceID(), out var value))
			{
				Vector3 size = ((Bounds)(ref value)).size;
				float magnitude = ((Vector3)(ref size)).magnitude;
				if ((!(magnitude > 5f) || ((Component)renderer).gameObject.isStatic) && magnitude > 3f)
				{
					_occluderBounds.Add(value);
				}
			}
		}
		UpdateOcclusionGrid(position, ((Component)cam).transform.forward);
	}

	private void UpdateOcclusionGrid(Vector3 camPos, Vector3 camForward)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_00af: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		int value = OcclusionGridSize.Value;
		float value2 = RendererMaxDistance.Value;
		float num = value2 * 2f / (float)value;
		Array.Clear(_occlusionGrid, 0, _occlusionGrid.Length);
		foreach (Bounds occluderBound in _occluderBounds)
		{
			Bounds current = occluderBound;
			Vector3 val = ((Bounds)(ref current)).center - camPos;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 1f || magnitude > value2)
			{
				continue;
			}
			float num2 = Vector3.Angle(camForward, ((Vector3)(ref val)).normalized);
			if (num2 > 60f)
			{
				continue;
			}
			Vector3 val2 = ((Bounds)(ref current)).center - camPos;
			int num3 = Mathf.Clamp((int)((val2.x + value2) / num), 0, value - 1);
			int num4 = Mathf.Clamp((int)((val2.z + value2) / num), 0, value - 1);
			Vector3 size = ((Bounds)(ref current)).size;
			int num5 = Mathf.CeilToInt(((Vector3)(ref size)).magnitude / num);
			for (int i = -num5; i <= num5; i++)
			{
				for (int j = -num5; j <= num5; j++)
				{
					int num6 = Mathf.Clamp(num3 + i, 0, value - 1);
					int num7 = Mathf.Clamp(num4 + j, 0, value - 1);
					_occlusionGrid[num6, num7] = true;
				}
			}
		}
	}

	private bool IsOccluded(int objectId, Bounds bounds, Vector3 camPos)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00e3: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		if (!SoftwareOcclusion.Value)
		{
			return false;
		}
		int value = OcclusionGridSize.Value;
		float value2 = RendererMaxDistance.Value;
		float num = value2 * 2f / (float)value;
		Vector3 val = ((Bounds)(ref bounds)).center - camPos;
		int num2 = Mathf.Clamp((int)((val.x + value2) / num), 0, value - 1);
		int num3 = Mathf.Clamp((int)((val.z + value2) / num), 0, value - 1);
		if (_occlusionGrid[num2, num3])
		{
			float magnitude = ((Vector3)(ref val)).magnitude;
			foreach (Bounds occluderBound in _occluderBounds)
			{
				Bounds current = occluderBound;
				Vector3 val2 = ((Bounds)(ref current)).center - camPos;
				float magnitude2 = ((Vector3)(ref val2)).magnitude;
				if (!(magnitude2 < magnitude - 2f))
				{
					continue;
				}
				Vector3 val3 = ((Bounds)(ref bounds)).center - camPos;
				Vector3 val4 = ((Bounds)(ref current)).center - camPos;
				if (Vector3.Angle(val3, val4) < 15f)
				{
					val2 = ((Bounds)(ref current)).size;
					float magnitude3 = ((Vector3)(ref val2)).magnitude;
					val2 = ((Bounds)(ref bounds)).size;
					if (magnitude3 > ((Vector3)(ref val2)).magnitude * 0.5f)
					{
						_occludedObjects.Add(objectId);
						return true;
					}
				}
			}
		}
		_occludedObjects.Remove(objectId);
		return false;
	}

	private void ResetOcclusionGrid()
	{
		Array.Clear(_occlusionGrid, 0, _occlusionGrid.Length);
		_occluderBounds.Clear();
		_occludedObjects.Clear();
	}

	private void DoPhysicsCulling(Camera cam)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		if (!RigidbodySleep.Value)
		{
			return;
		}
		Vector3 position = ((Component)cam).transform.position;
		float num = PhysicsCullDistance.Value * PhysicsCullDistance.Value;
		float num2 = (AggressivePhysicsSleep.Value ? 0.5f : PhysicsSleepThreshold.Value);
		for (int i = 0; i < _rigidbodies.Count; i++)
		{
			Component val = _rigidbodies[i];
			if ((Object)(object)val == (Object)null || !val.gameObject.activeInHierarchy || GetRigidbodyIsKinematic(val) || IsPlayerOrRig(((Object)val.transform.root).name))
			{
				continue;
			}
			Vector3 rigidbodyPosition = GetRigidbodyPosition(val);
			Vector3 val2 = rigidbodyPosition - position;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			int instanceID = ((Object)val).GetInstanceID();
			if (sqrMagnitude > num)
			{
				if (!RigidbodyIsSleeping(val))
				{
					if (!_originalRbSleepThresholds.ContainsKey(instanceID))
					{
						_originalRbSleepThresholds[instanceID] = GetRigidbodySleepThreshold(val);
					}
					float value = num2 * (UltraMode.Value ? 20f : 10f);
					SetRigidbodySleepThreshold(val, value);
					RigidbodySleepCall(val);
					_sleepingRigidbodies.Add(instanceID);
					if (InterpolationOptimization.Value)
					{
						SetRigidbodyInterpolation(val, 0);
					}
				}
			}
			else if (_sleepingRigidbodies.Contains(instanceID))
			{
				if (_originalRbSleepThresholds.TryGetValue(instanceID, out var value2))
				{
					SetRigidbodySleepThreshold(val, value2);
				}
				if (InterpolationOptimization.Value)
				{
					SetRigidbodyInterpolation(val, 1);
				}
				_sleepingRigidbodies.Remove(instanceID);
			}
		}
		if (ContactPairOptimization.Value)
		{
			OptimizeContactPairs(position, num);
		}
	}

	private void OptimizeContactPairs(Vector3 camPos, float maxDistSq)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//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)
		foreach (Component collider in _colliders)
		{
			if ((Object)(object)collider == (Object)null)
			{
				continue;
			}
			Vector3 val = collider.transform.position - camPos;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			if (sqrMagnitude > maxDistSq * 4f)
			{
				Behaviour val2 = (Behaviour)(object)((collider is Behaviour) ? collider : null);
				if ((Object)(object)val2 != (Object)null && val2.enabled && IsPlayerOrRig(((Object)collider.transform.root).name))
				{
				}
			}
		}
	}

	private void DoSleepSystems(Camera cam)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)cam).transform.position;
		Vector3 val2;
		if (PropSleep.Value)
		{
			float num = PropSleepDistance.Value * PropSleepDistance.Value;
			for (int i = 0; i < _props.Count; i++)
			{
				Component val = _props[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				val2 = val.transform.position - position;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID = ((Object)val).GetInstanceID();
				if (sqrMagnitude > num)
				{
					if (val.gameObject.activeSelf && !_sleepingProps.Contains(instanceID))
					{
						SetPropSleep(val, sleep: true);
						_sleepingProps.Add(instanceID);
					}
				}
				else if (_sleepingProps.Contains(instanceID))
				{
					SetPropSleep(val, sleep: false);
					_sleepingProps.Remove(instanceID);
				}
			}
		}
		if (NPCSleep.Value)
		{
			float num2 = NPCSleepDistance.Value * NPCSleepDistance.Value;
			for (int j = 0; j < _npcs.Count; j++)
			{
				Component val3 = _npcs[j];
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				val2 = val3.transform.position - position;
				float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
				int instanceID2 = ((Object)val3).GetInstanceID();
				if (sqrMagnitude2 > num2)
				{
					if (!_sleepingNPCs.Contains(instanceID2))
					{
						SetNPCSleep(val3, sleep: true);
						_sleepingNPCs.Add(instanceID2);
					}
				}
				else if (_sleepingNPCs.Contains(instanceID2))
				{
					SetNPCSleep(val3, sleep: false);
					_sleepingNPCs.Remove(instanceID2);
				}
			}
		}
		if (!NavMeshAgentSleep.Value)
		{
			return;
		}
		float num3 = NPCSleepDistance.Value * NPCSleepDistance.Value;
		for (int k = 0; k < _navMeshAgents.Count; k++)
		{
			Component val4 = _navMeshAgents[k];
			if ((Object)(object)val4 == (Object)null || !val4.gameObject.activeInHierarchy)
			{
				continue;
			}
			val2 = val4.transform.position - position;
			float sqrMagnitude3 = ((Vector3)(ref val2)).sqrMagnitude;
			int instanceID3 = ((Object)val4).GetInstanceID();
			Behaviour val5 = (Behaviour)(object)((val4 is Behaviour) ? val4 : null);
			if (sqrMagnitude3 > num3)
			{
				if ((Object)(object)val5 != (Object)null && val5.enabled)
				{
					val5.enabled = false;
					_sleepingNavMeshAgents.Add(instanceID3);
				}
			}
			else if (_sleepingNavMeshAgents.Contains(instanceID3) && (Object)(object)val5 != (Object)null)
			{
				val5.enabled = true;
				_sleepingNavMeshAgents.Remove(instanceID3);
			}
		}
	}

	private void SetPropSleep(Component prop, bool sleep)
	{
		Il2CppArrayBase<Renderer> componentsInChildren = prop.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer item in componentsInChildren)
		{
			if ((Object)(object)item != (Object)null)
			{
				item.enabled = !sleep;
			}
		}
		List<Component> list = SafeGetComponentsInChildren(prop.gameObject, "Rigidbody");
		foreach (Component item2 in list)
		{
			if (!((Object)(object)item2 == (Object)null) && !GetRigidbodyIsKinematic(item2))
			{
				if (sleep)
				{
					RigidbodySleepCall(item2);
					SetRigidbodyInterpolation(item2, 0);
				}
				else
				{
					RigidbodyWakeUpCall(item2);
					SetRigidbodyInterpolation(item2, 1);
				}
			}
		}
		List<Component> list2 = SafeGetComponentsInChildren(prop.gameObject, "ParticleSystem");
		foreach (Component item3 in list2)
		{
			if (!((Object)(object)item3 == (Object)null) && sleep)
			{
				StopParticle(item3);
			}
		}
	}

	private void SetNPCSleep(Component npc, bool sleep)
	{
		Il2CppArrayBase<Behaviour> componentsInChildren = npc.GetComponentsInChildren<Behaviour>(true);
		foreach (Behaviour item in componentsInChildren)
		{
			if (!((Object)(object)item == (Object)null))
			{
				string name = ((object)item).GetType().Name;
				if (name.Contains("AI") || name.Contains("Brain") || name.Contains("Behaviour") || name.Contains("Agent") || name.Contains("Controller"))
				{
					item.enabled = !sleep;
				}
			}
		}
		List<Component> list = SafeGetComponentsInChildren(npc.gameObject, "Animator");
		foreach (Component item2 in list)
		{
			if ((Object)(object)item2 != (Object)null)
			{
				SetAnimatorCullingMode(item2, sleep ? 2 : 0);
			}
		}
		List<Component> list2 = SafeGetComponentsInChildren(npc.gameObject, "Rigidbody");
		foreach (Component item3 in list2)
		{
			if ((Object)(object)item3 != (Object)null && !GetRigidbodyIsKinematic(item3) && sleep)
			{
				SetRigidbodySleepThreshold(item3, 1f);
				RigidbodySleepCall(item3);
			}
		}
	}

	private void FindPlayerReferences()
	{
		if (_playerRigManager != null && !((Object)(object)_playerHead == (Object)null))
		{
			return;
		}
		try
		{
			Il2CppArrayBase<Component> val = Object.FindObjectsOfType<Component>();
			foreach (Component item in val)
			{
				if (!((Object)(object)item != (Object)null) || !(((object)item).GetType().FullName == "SLZ.Rig.RigManager"))
				{
					continue;
				}
				_playerRigManager = item;
				Type type = ((object)item).GetType();
				PropertyInfo property = type.GetProperty("physicsRig");
				if (!(property != null))
				{
					break;
				}
				object value = property.GetValue(item);
				if (value != null)
				{
					PropertyInfo property2 = value.GetType().GetProperty("m_head");
					if (property2 != null)
					{
						ref Transform playerHead = ref _playerHead;
						object? value2 = property2.GetValue(value);
						playerHead = (Transform)((value2 is Transform) ? value2 : null);
					}
				}
				break;
			}
		}
		catch
		{
		}
	}

	private void DoPlayerOptimizations(Camera cam)
	{
		//IL_0016: 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)
		if (_playerRigManager != null)
		{
			Vector3 position = ((Component)cam).transform.position;
			if (IKOptimization.Value)
			{
				OptimizePlayerIK();
			}
			if (HandTrackingOptimize.Value)
			{
				OptimizeHandTracking();
			}
			if (AvatarLODOptimize.Value)
			{
				OptimizeAvatarLOD();
			}
		}
	}

	private void OptimizePlayerIK()
	{
		if (_averageFrameTime > 0.02f)
		{
			foreach (Component ikSolver in _ikSolvers)
			{
				if (!((Object)(object)ikSolver == (Object)null))
				{
					TrySetProperty(ikSolver, "iterations", 2);
				}
			}
			return;
		}
		foreach (Component ikSolver2 in _ikSolvers)
		{
			if (!((Object)(object)ikSolver2 == (Object)null))
			{
				TrySetProperty(ikSolver2, "iterations", 4);
			}
		}
	}

	private void OptimizeHandTracking()
	{
	}

	private void OptimizeAvatarLOD()
	{
		if (_playerRigManager == null)
		{
			return;
		}
		try
		{
			object playerRigManager = _playerRigManager;
			Component val = (Component)((playerRigManager is Component) ? playerRigManager : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Il2CppArrayBase<SkinnedMeshRenderer> componentsInChildren = val.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer item in componentsInChildren)
			{
				if (!((Object)(object)item == (Object)null))
				{
					if (_averageFrameTime > 0.025f)
					{
						item.quality = (SkinQuality)2;
						item.updateWhenOffscreen = false;
					}