Decompiled source of FPSBooster TarOnHook v0.1.0

FPSBooster.dll

Decompiled 30 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("TarOnHook")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FPSBooster")]
[assembly: AssemblyTitle("FPSBooster")]
[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 FPSBooster
{
	[HarmonyPatch(typeof(PlayerController))]
	internal static class ExamplePlayerControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void Start_Prefix(PlayerController __instance)
		{
			FPSBooster.InstanceLogger.LogDebug((object)$"{__instance} Start Prefix");
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Start_Postfix(PlayerController __instance)
		{
			FPSBooster.InstanceLogger.LogDebug((object)$"{__instance} Start Postfix");
		}
	}
	[BepInPlugin("TarOnHook.FPSBooster", "FPSBooster", "1.0.0")]
	public class FPSBooster : BaseUnityPlugin
	{
		internal static FPSBooster Instance;

		private ConfigEntry<int> targetFPS = null;

		private ConfigEntry<bool> vsync = null;

		private ConfigEntry<bool> showCredit = null;

		private ConfigEntry<string> creditPosition = null;

		private ConfigEntry<bool> showFPS = null;

		private ConfigEntry<string> fpsPosition = null;

		private ConfigEntry<int> shadowQuality = null;

		private ConfigEntry<float> shadowDistance = null;

		private ConfigEntry<float> renderDistance = null;

		private ConfigEntry<int> antiAliasing = null;

		private ConfigEntry<bool> effects = null;

		private ConfigEntry<float> lodBias = null;

		private float deltaTime;

		internal static ManualLogSource InstanceLogger => ((BaseUnityPlugin)Instance).Logger;

		private void Awake()
		{
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			Instance = this;
			targetFPS = ((BaseUnityPlugin)this).Config.Bind<int>("FPS", "TargetFPS", 60, (ConfigDescription)null);
			vsync = ((BaseUnityPlugin)this).Config.Bind<bool>("FPS", "DisableVSync", true, (ConfigDescription)null);
			showCredit = ((BaseUnityPlugin)this).Config.Bind<bool>("Credits", "ShowCredit", true, (ConfigDescription)null);
			creditPosition = ((BaseUnityPlugin)this).Config.Bind<string>("Credits", "Position", "TopLeft", (ConfigDescription)null);
			showFPS = ((BaseUnityPlugin)this).Config.Bind<bool>("FPS Display", "ShowFPS", true, (ConfigDescription)null);
			fpsPosition = ((BaseUnityPlugin)this).Config.Bind<string>("FPS Display", "Position", "TopRight", (ConfigDescription)null);
			shadowQuality = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "ShadowQuality", 1, (ConfigDescription)null);
			shadowDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Graphics", "ShadowDistance", 25f, (ConfigDescription)null);
			renderDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Graphics", "RenderDistance", 500f, (ConfigDescription)null);
			antiAliasing = ((BaseUnityPlugin)this).Config.Bind<int>("Graphics", "AntiAliasing", 0, (ConfigDescription)null);
			effects = ((BaseUnityPlugin)this).Config.Bind<bool>("Graphics", "Effects", true, (ConfigDescription)null);
			lodBias = ((BaseUnityPlugin)this).Config.Bind<float>("Graphics", "LODBias", 1f, (ConfigDescription)null);
			Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			val.PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
			ApplySettings();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"FPSBooster by TarOnHook loaded!");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			ApplySettings();
		}

		private void Update()
		{
			deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;
			Application.targetFrameRate = targetFPS.Value;
			QualitySettings.vSyncCount = ((!vsync.Value) ? 1 : 0);
			ApplySettings();
		}

		private void ApplySettings()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			int value = shadowQuality.Value;
			if (1 == 0)
			{
			}
			ShadowQuality shadows = (ShadowQuality)(value switch
			{
				0 => 0, 
				1 => 1, 
				_ => 2, 
			});
			if (1 == 0)
			{
			}
			QualitySettings.shadows = shadows;
			QualitySettings.shadowDistance = Mathf.Clamp(shadowDistance.Value, 0f, 150f);
			QualitySettings.antiAliasing = antiAliasing.Value;
			QualitySettings.lodBias = Mathf.Clamp(lodBias.Value, 0.2f, 3f);
			Camera[] allCameras = Camera.allCameras;
			foreach (Camera val in allCameras)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.farClipPlane = Mathf.Clamp(renderDistance.Value, 50f, 2000f);
				}
			}
			QualitySettings.softParticles = effects.Value;
		}

		private void OnGUI()
		{
			if (showCredit.Value)
			{
				DrawText("Mod von TarOnHook", creditPosition.Value, 15, 0);
			}
			if (showFPS.Value)
			{
				float num = ((deltaTime > 0f) ? (1f / deltaTime) : 0f);
				DrawText($"FPS: {Mathf.RoundToInt(num)}", fpsPosition.Value, 15, 30);
			}
		}

		private void DrawText(string content, string position, int fontSize, int verticalOffset)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = fontSize,
				fontStyle = (FontStyle)1
			};
			val.normal.textColor = Color.white;
			GUIStyle val2 = val;
			float num = 250f;
			float num2 = 30f;
			if (1 == 0)
			{
			}
			float num3 = ((!(position == "TopRight") && !(position == "BottomRight")) ? 10f : ((float)Screen.width - num - 10f));
			if (1 == 0)
			{
			}
			float num4 = num3;
			if (1 == 0)
			{
			}
			num3 = ((!(position == "BottomLeft") && !(position == "BottomRight")) ? ((float)(10 + verticalOffset)) : ((float)Screen.height - num2 - 10f - (float)verticalOffset));
			if (1 == 0)
			{
			}
			float num5 = num3;
			GUI.Label(new Rect(num4, num5, num, num2), content, val2);
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}
	}
}