Decompiled source of Flash Time v1.0.2

plugins/FlashTime.dll

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

[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("BellaModsGames")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FlashSpeedMod")]
[assembly: AssemblyTitle("FlashSpeedMod")]
[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.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]
	[Microsoft.CodeAnalysis.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]
	[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 FlashSpeedModNamespace
{
	[BepInPlugin("com.BellaModsGames.flashtime", "Flash Time", "1.0.0")]
	public class FlashSpeedMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerController))]
		private class PlayerControllerPatches
		{
			private static bool wasFlashActive;

			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			private static void Update_Prefix(PlayerController __instance)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				if (toggleKey == null)
				{
					return;
				}
				if (Input.GetKey(toggleKey.Value))
				{
					if (!wasKeyPressed)
					{
						isFlashSystemEnabled = !isFlashSystemEnabled;
						ManualLogSource? staticLogger = StaticLogger;
						if (staticLogger != null)
						{
							staticLogger.LogInfo((object)("Flash Time " + (isFlashSystemEnabled ? "enabled" : "disabled")));
						}
						wasKeyPressed = true;
					}
				}
				else
				{
					wasKeyPressed = false;
				}
				if (enableSlowMotion != null && enableSlowMotion.Value && slowMotionKey != null && IsFlashActive)
				{
					if (Input.GetKey(slowMotionKey.Value))
					{
						if (!isSlowMotionActive && slowMotionTimeScale != null)
						{
							Time.timeScale = slowMotionTimeScale.Value;
							isSlowMotionActive = true;
							ManualLogSource? staticLogger2 = StaticLogger;
							if (staticLogger2 != null)
							{
								staticLogger2.LogInfo((object)"Activated slow motion");
							}
						}
					}
					else if (isSlowMotionActive)
					{
						Time.timeScale = originalTimeScale;
						isSlowMotionActive = false;
						ManualLogSource? staticLogger3 = StaticLogger;
						if (staticLogger3 != null)
						{
							staticLogger3.LogInfo((object)"Deactivated slow motion");
						}
					}
				}
				else if (isSlowMotionActive)
				{
					Time.timeScale = originalTimeScale;
					isSlowMotionActive = false;
				}
			}

			[HarmonyPatch("FixedUpdate")]
			[HarmonyPrefix]
			private static bool FixedUpdate_Prefix(PlayerController __instance)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				if (speedBoostKey == null || flashSpeedMultiplier == null)
				{
					return true;
				}
				if (!valuesStored)
				{
					originalMoveSpeed = __instance.MoveSpeed;
					originalSprintSpeed = __instance.SprintSpeed;
					originalSprintAcceleration = __instance.SprintAcceleration;
					originalEnergyDrain = __instance.EnergySprintDrain;
					valuesStored = true;
				}
				bool key = Input.GetKey(speedBoostKey.Value);
				IsFlashActive = isFlashSystemEnabled && key;
				if (IsFlashActive)
				{
					if (!wasFlashActive)
					{
						ManualLogSource? staticLogger = StaticLogger;
						if (staticLogger != null)
						{
							staticLogger.LogInfo((object)"Flash speed activated!");
						}
					}
					__instance.MoveSpeed = originalMoveSpeed * flashSpeedMultiplier.Value;
					__instance.SprintSpeed = originalSprintSpeed * flashSpeedMultiplier.Value;
					__instance.SprintAcceleration = 10f;
					__instance.EnergySprintDrain = 0f;
					wasFlashActive = true;
				}
				else if (wasFlashActive)
				{
					__instance.MoveSpeed = originalMoveSpeed;
					__instance.SprintSpeed = originalSprintSpeed;
					__instance.SprintAcceleration = originalSprintAcceleration;
					__instance.EnergySprintDrain = originalEnergyDrain;
					wasFlashActive = false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CameraAim))]
		private class CameraAimPatches
		{
			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			private static bool Update_Prefix(CameraAim __instance)
			{
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				if (isSlowMotionActive && slowMotionTimeScale != null && slowMotionLookMultiplier != null)
				{
					float num = SemiFunc.InputMouseX();
					float num2 = SemiFunc.InputMouseY();
					float num3 = 1f / slowMotionTimeScale.Value;
					float num4 = 0.2f;
					__instance.aimHorizontal += num * __instance.AimSpeedMouse * num3 * num4 * slowMotionLookMultiplier.Value;
					__instance.aimVertical += (0f - num2) * __instance.AimSpeedMouse * num3 * num4 * slowMotionLookMultiplier.Value;
					__instance.aimVertical = Mathf.Clamp(__instance.aimVertical, -70f, 80f);
					((Component)__instance).transform.localRotation = Quaternion.Euler(__instance.aimVertical, __instance.aimHorizontal, 0f);
					return false;
				}
				return true;
			}
		}

		public static ConfigEntry<float>? normalSpeedMultiplier;

		public static ConfigEntry<float>? flashSpeedMultiplier;

		public static ConfigEntry<KeyCode>? speedBoostKey;

		public static ConfigEntry<KeyCode>? toggleKey;

		public static ConfigEntry<bool>? enableSlowMotion;

		public static ConfigEntry<float>? slowMotionTimeScale;

		public static ConfigEntry<KeyCode>? slowMotionKey;

		public static ConfigEntry<float>? slowMotionLookMultiplier;

		private ManualLogSource? modLogger;

		private static float originalMoveSpeed;

		private static float originalSprintSpeed;

		private static float originalSprintAcceleration;

		private static float originalEnergyDrain;

		private static float originalTimeScale;

		private static bool valuesStored;

		public static bool isFlashSystemEnabled;

		private static bool wasKeyPressed;

		public static bool isSlowMotionActive;

		public static ManualLogSource? StaticLogger { get; private set; }

		public static FlashSpeedMod? Instance { get; private set; }

		public static bool IsFlashActive { get; private set; }

		private void Awake()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			Instance = this;
			modLogger = Logger.CreateLogSource("Flash Time");
			StaticLogger = modLogger;
			normalSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "Normal Speed Multiplier", 1f, new ConfigDescription("Base movement speed multiplier", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 2f), Array.Empty<object>()));
			flashSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "Flash Speed Multiplier", 3f, new ConfigDescription("Speed multiplier when using Flash powers", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 6f), Array.Empty<object>()));
			speedBoostKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Speed Boost Key", (KeyCode)304, "Key to activate Flash speed");
			toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Toggle Flash System", (KeyCode)120, "Key to toggle Flash system on/off");
			enableSlowMotion = ((BaseUnityPlugin)this).Config.Bind<bool>("Slow Motion", "Enable Slow Motion", true, "Enable slow motion feature while using Flash speed");
			slowMotionTimeScale = ((BaseUnityPlugin)this).Config.Bind<float>("Slow Motion", "Slow Motion Time Scale", 0.2f, new ConfigDescription("Time scale when slow motion is active (lower = slower)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 0.5f), Array.Empty<object>()));
			slowMotionKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Slow Motion Key", (KeyCode)324, "Key to activate slow motion (while using Flash speed)");
			slowMotionLookMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Slow Motion", "Look Sensitivity Multiplier", 0.3f, new ConfigDescription("Additional look sensitivity multiplier during slow motion", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			originalTimeScale = Time.timeScale;
			Harmony val = new Harmony("com.BellaModsGames.flashtime");
			val.PatchAll();
			modLogger.LogInfo((object)"Flash Time initialized!");
			((Component)this).gameObject.AddComponent<FlashTimeGUI>();
		}
	}
	public class FlashTimeGUI : MonoBehaviour
	{
		private void OnGUI()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect((float)(Screen.width - 200), 10f, 190f, 20f), "Flash Time: " + (FlashSpeedMod.isFlashSystemEnabled ? "Enabled" : "Disabled"));
			if (FlashSpeedMod.isSlowMotionActive)
			{
				GUI.Label(new Rect((float)(Screen.width - 200), 30f, 190f, 20f), "Slow Motion Active");
			}
		}
	}
}