Decompiled source of NoRandomSlowDown v1.0.0

Mods/NoRandomSlowDown.dll

Decompiled 6 days 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 BoneLib.BoneMenu;
using MelonLoader;
using MelonLoader.Preferences;
using NoRandomSlowDown;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(NoRandomSlowDownMod), "No Random Slow Down", "1.0.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("Fixes the issue where the game appears to enter slow motion at very low framerates.")]
[assembly: AssemblyTitle("No Random Slow Down")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace NoRandomSlowDown;

public class NoRandomSlowDownMod : MelonMod
{
	public const string Version = "1.0.0";

	private static bool _preferencesSetup = false;

	private static float _defaultMaximumDeltaTime = 1f / 30f;

	public const float OverrideMaximumDeltaTime = 1f / 3f;

	public static MelonPreferences_Category MelonPrefCategory { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

	public static bool IsEnabled { get; private set; } = true;


	public static Page MainPage { get; private set; }

	public static BoolElement EnabledElement { get; private set; }

	public override void OnInitializeMelon()
	{
		SetupMelonPrefs();
		SetupBoneMenu();
		_defaultMaximumDeltaTime = Time.maximumDeltaTime;
		ApplyMaximumDeltaTime();
	}

	public static void SetupMelonPrefs()
	{
		MelonPrefCategory = MelonPreferences.CreateCategory("NoRandomSlowDown");
		MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("IsEnabled", IsEnabled, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsEnabled = MelonPrefEnabled.Value;
		_preferencesSetup = true;
	}

	public static void SetupBoneMenu()
	{
		//IL_000a: 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)
		MainPage = Page.Root.CreatePage("No Random Slow Down", Color.yellow, 0, true);
		EnabledElement = MainPage.CreateBool("Enabled", Color.cyan, IsEnabled, (Action<bool>)OnSetEnabled);
	}

	private static void OnSetEnabled(bool value)
	{
		IsEnabled = value;
		MelonPrefEnabled.Value = value;
		MelonPrefCategory.SaveToFile(false);
		ApplyMaximumDeltaTime();
	}

	private static void ApplyMaximumDeltaTime()
	{
		if (IsEnabled)
		{
			Time.maximumDeltaTime = 1f / 3f;
		}
		else
		{
			Time.maximumDeltaTime = _defaultMaximumDeltaTime;
		}
	}

	public override void OnPreferencesLoaded()
	{
		if (_preferencesSetup)
		{
			IsEnabled = MelonPrefEnabled.Value;
			EnabledElement.Value = IsEnabled;
		}
	}
}