Decompiled source of Bullet Time v1.1.0

Mods/BulletTime.dll

Decompiled 2 weeks 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;
using BoneLib.BoneMenu;
using BulletTime;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Bullet Time")]
[assembly: MelonInfo(typeof(BulletTimeMod), "Bullet Time", "1.1.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace BulletTime
{
	public class BulletTimeMod : MelonMod
	{
		public const string Version = "1.1.0";

		private static bool _preferencesSetup;

		public static bool IsEnabled { get; private set; }

		public static int MaxSlowMo { get; private set; }

		public static bool SpeedTime { get; private set; }

		public static MelonPreferences_Category MelonPrefCategory { get; private set; }

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

		public static MelonPreferences_Entry<int> MelonPrefMaxSlowMo { get; private set; }

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

		public static Page MainPage { get; private set; }

		public static BoolElement BoneMenuEnabledElement { get; private set; }

		public static IntElement BoneMenuMaxSlowMoElement { get; private set; }

		public static BoolElement BoneMenuSpeedTimeElement { get; private set; }

		public override void OnInitializeMelon()
		{
			Hooking.OnLevelLoaded += OnLevelLoaded;
			SetupMelonPrefs();
			SetupBoneMenu();
		}

		public static void SetupMelonPrefs()
		{
			MelonPrefCategory = MelonPreferences.CreateCategory("BulletTime");
			MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("IsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MelonPrefMaxSlowMo = MelonPrefCategory.CreateEntry<int>("MaxSlowMo", 6, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MelonPrefSpeedTime = MelonPrefCategory.CreateEntry<bool>("SpeedTime", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			IsEnabled = MelonPrefEnabled.Value;
			MaxSlowMo = MelonPrefMaxSlowMo.Value;
			SpeedTime = MelonPrefSpeedTime.Value;
			_preferencesSetup = true;
		}

		public override void OnPreferencesLoaded()
		{
			if (_preferencesSetup)
			{
				IsEnabled = MelonPrefEnabled.Value;
				BoneMenuEnabledElement.Value = IsEnabled;
				MaxSlowMo = MelonPrefMaxSlowMo.Value;
				BoneMenuMaxSlowMoElement.Value = MaxSlowMo;
				SpeedTime = MelonPrefSpeedTime.Value;
				BoneMenuSpeedTimeElement.Value = SpeedTime;
				OnValueChanged();
			}
		}

		public static void OnLevelLoaded(LevelInfo info)
		{
			OnValueChanged();
		}

		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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			MainPage = Page.Root.CreatePage("Bullet Time", Color.green, 0, true);
			BoneMenuEnabledElement = MainPage.CreateBool("Mod Toggle", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
			BoneMenuMaxSlowMoElement = MainPage.CreateInt("Max Slow Mo", Color.yellow, MaxSlowMo, 1, 0, 32, (Action<int>)OnSetMax);
			BoneMenuSpeedTimeElement = MainPage.CreateBool("Speed Time", Color.yellow, SpeedTime, (Action<bool>)OnSetSpeedTime);
		}

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

		public static void OnSetSpeedTime(bool value)
		{
			SpeedTime = value;
			MelonPrefSpeedTime.Value = value;
			MelonPrefCategory.SaveToFile(false);
			OnValueChanged();
		}

		public static void OnSetMax(int value)
		{
			MaxSlowMo = value;
			MelonPrefMaxSlowMo.Value = value;
			MelonPrefCategory.SaveToFile(false);
			OnValueChanged();
		}

		public static void OnValueChanged()
		{
			if (IsEnabled)
			{
				TimeManager.max_intensity = Mathf.Pow(2f, (float)MaxSlowMo);
				TimeManager.max_timeScaleStep = MaxSlowMo;
			}
			else
			{
				TimeManager.max_intensity = 8f;
				TimeManager.max_timeScaleStep = 3;
			}
		}
	}
}
namespace BulletTime.Patching
{
	[HarmonyPatch(typeof(Time))]
	public static class TimePatches
	{
		[HarmonyPatch("timeScale")]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		public static void SetTimescale(ref float value)
		{
			if (BulletTimeMod.IsEnabled && BulletTimeMod.SpeedTime && value < 1f && value > 0f)
			{
				value = 1f / value;
			}
		}
	}
	[HarmonyPatch(typeof(OpenControllerRig))]
	public static class OpenControllerRigPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("TimeInput")]
		public static bool TimeInputPrefix(OpenControllerRig __instance, bool down, bool up, bool touch)
		{
			if (!BulletTimeMod.IsEnabled)
			{
				return true;
			}
			if (!down)
			{
				return true;
			}
			if (TimeManager.CurrentTimeScaleStep >= 3)
			{
				TimeManager.DECREASE_TIMESCALE();
				__instance._timeInput = false;
				return false;
			}
			if (TimeManager.CurrentTimeScaleStep >= TimeManager.max_timeScaleStep)
			{
				__instance._timeInput = false;
				return false;
			}
			return true;
		}
	}
}