Decompiled source of NoFrameSkip v1.0.1

plugins/NoFrameSkip.dll

Decompiled a month 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoFrameSkip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoFrameSkip")]
[assembly: AssemblyTitle("NoFrameSkip")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 NoFrameSkip
{
	[BepInPlugin("McAwesome.ROR2.NoFrameSkip", "NoFrameSkip", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NoFrameSkip : BaseUnityPlugin
	{
		public const string PluginGUID = "McAwesome.ROR2.NoFrameSkip";

		public const string PluginAuthor = "McAwesome";

		public const string PluginName = "NoFrameSkip";

		public const string PluginVersion = "1.0.0";

		internal ConfigEntry<float> configMaxDeltaTime;

		private float? configUpdateTimer;

		public static NoFrameSkip Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public float DefaultMaxDeltaTime { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			configMaxDeltaTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "maxDeltaTime", 0f, "The max length of time that can pass between two rendered frames.\nUnity default is 0.333.\nSet to 0 to ensure no more than 1 physics update happens per frame.\nSet negative to leave unchanged.");
			Logger.LogInfo((object)"McAwesome.ROR2.NoFrameSkip v1.0.0 has loaded!");
		}

		private void Start()
		{
			DefaultMaxDeltaTime = Time.maximumDeltaTime;
			configMaxDeltaTime.SettingChanged += ConfigUpdated;
			bool flag = false;
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (!(value.Metadata.GUID == "com.rune580.riskofoptions"))
				{
					continue;
				}
				flag = true;
				Version version = value.Metadata.Version;
				if (version >= Version.Parse("2.4.2") && version < Version.Parse("3.0.0"))
				{
					RiskOfOptionsCompatibility.Initialize();
					break;
				}
				try
				{
					RiskOfOptionsCompatibility.Initialize();
					Logger.LogWarning((object)$"Risk of Options detected, but version may be incompatible (Found: {version}, Expected: >=2.4.2, <3.0.0");
				}
				catch
				{
					Logger.LogError((object)$"Risk of Options detected, but version is incompatible (Found: {version}, Expected: >=2.4.2, <3.0.0");
				}
				break;
			}
			if (!flag)
			{
				Logger.LogInfo((object)"Risk of Options not found");
			}
			UpdateMaximumDeltaTime();
		}

		private void Update()
		{
			float? num = configUpdateTimer;
			if (num.HasValue)
			{
				if (configUpdateTimer > 0f)
				{
					configUpdateTimer -= Time.unscaledDeltaTime;
					return;
				}
				UpdateMaximumDeltaTime();
				configUpdateTimer = null;
			}
		}

		private void ConfigUpdated(object sender, EventArgs e)
		{
			configUpdateTimer = 1f;
		}

		private void UpdateMaximumDeltaTime()
		{
			if (configMaxDeltaTime.Value < 0f)
			{
				Time.maximumDeltaTime = DefaultMaxDeltaTime;
				Logger.LogInfo((object)$"maxDeltaTime config is negative ({configMaxDeltaTime.Value}), leaving maximumDeltaTime unchanged ({Time.maximumDeltaTime})");
				return;
			}
			Time.maximumDeltaTime = configMaxDeltaTime.Value;
			Logger.LogInfo((object)$"Time.maximumDeltaTime set to {Time.maximumDeltaTime}");
			if (Time.maximumDeltaTime > configMaxDeltaTime.Value)
			{
				Logger.LogInfo((object)$"(Note: This is higher than the config value ({configMaxDeltaTime.Value}) because Time.maximumDeltaTime cannot be less than Time.fixedDeltaTime)");
			}
		}
	}
	internal static class RiskOfOptionsCompatibility
	{
		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void Initialize()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008e: Expected O, but got Unknown
			//IL_0093: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(NoFrameSkip.Instance.configMaxDeltaTime, new StepSliderConfig
			{
				name = "Maximum Delta Time",
				min = -1f / 60f,
				max = 0.5f,
				increment = 1f / 60f,
				restartRequired = false,
				FormatString = "{0:N3}"
			}));
			ConfigEntry<float> configMaxDeltaTime = NoFrameSkip.Instance.configMaxDeltaTime;
			FloatFieldConfig val = new FloatFieldConfig
			{
				name = "Maximum Delta Time",
				description = "Same as above but you can put in any number that you want",
				restartRequired = false
			};
			((NumericFieldConfig<float>)val).FormatString = "{0:N10}";
			ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(configMaxDeltaTime, val));
		}
	}
}