Decompiled source of FPSOptimizerMod v1.0.0

FPSOptimizerMod.dll

Decompiled 43 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FPSOptimizerMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FPSOptimizerMod")]
[assembly: AssemblyTitle("FPSOptimizerMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FPSOptimizerMod
{
	[BepInPlugin("FPSOptimizerMod", "FPSOptimizerMod", "1.0.0")]
	public class FPSOptimizerMod : BaseUnityPlugin
	{
		public static FPSOptimizerMod Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Application.SetStackTraceLogType((LogType)3, (StackTraceLogType)0);
			Application.SetStackTraceLogType((LogType)2, (StackTraceLogType)0);
			Application.SetStackTraceLogType((LogType)1, (StackTraceLogType)0);
			QualitySettings.vSyncCount = 0;
			QualitySettings.lodBias = 0.7f;
			QualitySettings.pixelLightCount = 1;
			QualitySettings.softParticles = false;
			QualitySettings.realtimeReflectionProbes = false;
			if (Harmony == null)
			{
				Harmony = new Harmony("FPSOptimizerMod");
			}
			Harmony.PatchAll();
			Logger.LogInfo((object)"FPSOptimizerMod v1.0.0 (Heavy Optimizer) loaded!");
		}
	}
	[HarmonyPatch]
	public class PerformancePatches
	{
		[HarmonyPatch(typeof(Debug), "Log", new Type[] { typeof(object) })]
		[HarmonyPrefix]
		private static bool SuppressUnityLogSpam()
		{
			return false;
		}

		[HarmonyPatch(typeof(Debug), "LogWarning", new Type[] { typeof(object) })]
		[HarmonyPrefix]
		private static bool SuppressUnityWarningSpam()
		{
			return false;
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void OnLobbyStart()
		{
			OptimizeScenePerformance("Lobby/Ship");
		}

		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void OnMoonGenerated()
		{
			OptimizeScenePerformance("Moon & Interior");
		}

		private static void OptimizeScenePerformance(string stage)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			QualitySettings.shadowDistance = 20f;
			QualitySettings.shadows = (ShadowQuality)1;
			HDAdditionalLightData[] array = Object.FindObjectsByType<HDAdditionalLightData>((FindObjectsSortMode)0);
			int num = 0;
			HDAdditionalLightData[] array2 = array;
			foreach (HDAdditionalLightData val in array2)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.affectsVolumetric = false;
					val.fadeDistance = 30f;
					val.shadowFadeDistance = 18f;
					if ((int)val.type == 2)
					{
						val.EnableShadows(false);
					}
					num++;
				}
			}
			Volume[] array3 = Object.FindObjectsByType<Volume>((FindObjectsSortMode)0);
			Volume[] array4 = array3;
			Fog val3 = default(Fog);
			VolumetricClouds val4 = default(VolumetricClouds);
			ScreenSpaceAmbientOcclusion val5 = default(ScreenSpaceAmbientOcclusion);
			foreach (Volume val2 in array4)
			{
				if (!((Object)(object)val2.profile == (Object)null))
				{
					if (val2.profile.TryGet<Fog>(ref val3))
					{
						((VolumeParameter<bool>)(object)val3.enableVolumetricFog).Override(false);
					}
					if (val2.profile.TryGet<VolumetricClouds>(ref val4))
					{
						((VolumeParameter<bool>)(object)val4.enable).Override(false);
					}
					if (val2.profile.TryGet<ScreenSpaceAmbientOcclusion>(ref val5))
					{
						((VolumeComponent)val5).active = false;
					}
				}
			}
			DecalProjector[] array5 = Object.FindObjectsByType<DecalProjector>((FindObjectsSortMode)0);
			int num2 = 0;
			DecalProjector[] array6 = array5;
			foreach (DecalProjector val6 in array6)
			{
				if ((Object)(object)val6 != (Object)null && ((Behaviour)val6).enabled)
				{
					((Behaviour)val6).enabled = false;
					num2++;
				}
			}
			Resources.UnloadUnusedAssets();
			FPSOptimizerMod.Logger.LogInfo((object)$"[{stage}] Optimized {num} lights, culled {num2} decals, and stripped volumetrics/SSAO.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FPSOptimizerMod";

		public const string PLUGIN_NAME = "FPSOptimizerMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace FPSOptimizerMod.Patches
{
	[HarmonyPatch(typeof(TVScript))]
	public class ExampleTVPatch
	{
		[HarmonyPatch("SwitchTVLocalClient")]
		[HarmonyPrefix]
		private static void SwitchTVPrefix(TVScript __instance)
		{
			StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
		}
	}
}