Decompiled source of SuperhotSilkSongMod v1.0.0

SuperhotSilkSongMod.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using InControl;
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: AssemblyCompany("SuperhotSilkSongMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SuperhotSilkSongMod")]
[assembly: AssemblyTitle("SuperhotSilkSongMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
public enum TimeControlMode
{
	MovementBased,
	InputBased
}
[BepInPlugin("lagerthon.SuperhotSilkSongMod", "Superhot Silksong Mod", "1.1.1")]
public class SuperhotSilkSongMod : BaseUnityPlugin
{
	private HeroController heroController;

	public static ConfigEntry<KeyCode> toggleKey;

	public static ConfigEntry<TimeControlMode> controlMode;

	public static ConfigEntry<bool> useKeyboard;

	public static ConfigEntry<bool> useController1;

	public static ConfigEntry<bool> useController2;

	public static ConfigEntry<KeyCode> keyLeft;

	public static ConfigEntry<KeyCode> keyRight;

	public static ConfigEntry<KeyCode> keyUp;

	public static ConfigEntry<KeyCode> keyDown;

	public static ConfigEntry<KeyCode> keyJump;

	public static ConfigEntry<KeyCode> keyAttack;

	public static ConfigEntry<KeyCode> keyDash;

	public static ConfigEntry<float> minSpeedMultiplier;

	public static ConfigEntry<float> maxSpeedMultiplier;

	public static ConfigEntry<float> growthFactor;

	public static ConfigEntry<float> decayFactor;

	private bool isGameActive;

	private bool modEnabled = false;

	private bool inputActive;

	private float inputStrength;

	private float joystickIntensity;

	private float inputActiveTime = 0f;

	private float inputInActiveTime = 0f;

	private const int sigmoidResolution = 1000;

	private float[] sigmoidRise;

	private float[] sigmoidFall;

	private int index;

	private float curve;

	private float lastGrowthFactor;

	private float lastDecayFactor;

	private void Awake()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Expected O, but got Unknown
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Expected O, but got Unknown
		toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Enable Mod", (KeyCode)303, "Key used to enable or disable the mod");
		controlMode = ((BaseUnityPlugin)this).Config.Bind<TimeControlMode>("General", "Speed Control Mode", TimeControlMode.MovementBased, "MovementBased = Time scales with Hornet's movement\nInputBased = Time scales with keyboard/controller input");
		minSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Min Speed Multiplier", 0.2f, new ConfigDescription("Minimum game speed when idle", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
		maxSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Speed", "Max Speed Multiplier", 1.5f, new ConfigDescription("Maximum game speed", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 2f), Array.Empty<object>()));
		growthFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "Growth Factor", 2.5f, new ConfigDescription("How quickly time accelerates when movement/input begins", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
		decayFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "Decay Factor", 2.5f, new ConfigDescription("How quickly time decays when idle", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
		useKeyboard = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "Use Keyboard", true, "Use keyboard input for InputBased mode");
		keyLeft = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 1", (KeyCode)276, (ConfigDescription)null);
		keyRight = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 2", (KeyCode)275, (ConfigDescription)null);
		keyUp = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 3", (KeyCode)273, (ConfigDescription)null);
		keyDown = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 4", (KeyCode)274, (ConfigDescription)null);
		keyJump = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 5", (KeyCode)122, (ConfigDescription)null);
		keyAttack = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 6", (KeyCode)120, (ConfigDescription)null);
		keyDash = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input.Keyboard", "Key 7", (KeyCode)99, (ConfigDescription)null);
		useController1 = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "Controller Mode 1", false, "Time ramps up while stick is held");
		useController2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "Controller Mode 2 (Analog)", false, "Time ramps up with stick intensity");
		useKeyboard.SettingChanged += delegate
		{
			if (useKeyboard.Value)
			{
				useController1.Value = false;
				useController2.Value = false;
			}
		};
		useController1.SettingChanged += delegate
		{
			if (useController1.Value)
			{
				useKeyboard.Value = false;
				useController2.Value = false;
			}
		};
		useController2.SettingChanged += delegate
		{
			if (useController2.Value)
			{
				useKeyboard.Value = false;
				useController1.Value = false;
			}
		};
		growthFactor.SettingChanged += delegate
		{
			SigmoidRise();
		};
		decayFactor.SettingChanged += delegate
		{
			SigmoidFall();
		};
		SigmoidRise();
		SigmoidFall();
		inputActiveTime = 1f;
		inputInActiveTime = 1f;
		inputActive = false;
		inputStrength = 1f;
		SceneManager.activeSceneChanged += OnSceneChanged;
	}

	private void SigmoidRise()
	{
		if (sigmoidRise == null || sigmoidRise.Length != 1001)
		{
			sigmoidRise = new float[1001];
		}
		float num = 10f * growthFactor.Value;
		for (int i = 0; i <= 1000; i++)
		{
			float num2 = (float)i / 1000f;
			sigmoidRise[i] = 1f / (1f + Mathf.Exp((0f - (num2 - 5f / num)) * num));
		}
	}

	private void SigmoidFall()
	{
		if (sigmoidFall == null || sigmoidFall.Length != 1001)
		{
			sigmoidFall = new float[1001];
		}
		float num = 10f * decayFactor.Value;
		for (int i = 0; i <= 1000; i++)
		{
			float num2 = (float)i / 1000f;
			sigmoidFall[i] = 1f / (1f + Mathf.Exp((0f - (num2 - 5f / num)) * num));
		}
	}

	private void OnSceneChanged(Scene oldScene, Scene newScene)
	{
		heroController = HeroController.instance;
		isGameActive = (Object)(object)heroController != (Object)null;
	}

	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(toggleKey.Value) && (Object)(object)heroController != (Object)null)
		{
			modEnabled = !modEnabled;
			if (!modEnabled)
			{
				Time.timeScale = 1f;
				Time.fixedDeltaTime = 0.02f;
			}
		}
		if (!modEnabled || !isGameActive || controlMode.Value != TimeControlMode.InputBased)
		{
			return;
		}
		if (useController1.Value || useController2.Value)
		{
			InputDevice activeDevice = InputManager.ActiveDevice;
			if (activeDevice != null)
			{
				Vector2 value = InputManager.ActiveDevice.LeftStick.Value;
				bool flag = OneAxisInputControl.op_Implicit((OneAxisInputControl)(object)InputManager.ActiveDevice.AnyButton);
				bool flag2 = OneAxisInputControl.op_Implicit((OneAxisInputControl)(object)InputManager.ActiveDevice.LeftBumper);
				bool flag3 = OneAxisInputControl.op_Implicit((OneAxisInputControl)(object)InputManager.ActiveDevice.RightBumper);
				bool flag4 = OneAxisInputControl.op_Implicit((OneAxisInputControl)(object)InputManager.ActiveDevice.LeftTrigger);
				bool flag5 = OneAxisInputControl.op_Implicit((OneAxisInputControl)(object)InputManager.ActiveDevice.RightTrigger);
				joystickIntensity = Mathf.Clamp01(((Vector2)(ref value)).magnitude);
				inputActive = joystickIntensity > 0.05f || flag || flag2 || flag3 || flag4 || flag5;
				inputStrength = (useController2.Value ? joystickIntensity : 1f);
			}
		}
		else if (useKeyboard.Value)
		{
			inputStrength = 1f;
			inputActive = Input.GetKey(keyLeft.Value) || Input.GetKey(keyRight.Value) || Input.GetKey(keyUp.Value) || Input.GetKey(keyDown.Value) || Input.GetKey(keyJump.Value) || Input.GetKey(keyAttack.Value) || Input.GetKey(keyDash.Value);
		}
	}

	private void LateUpdate()
	{
		if (!modEnabled || !isGameActive)
		{
			if (Time.timeScale != 1f)
			{
				Time.timeScale = 1f;
				Time.fixedDeltaTime = 0.02f;
			}
			return;
		}
		switch (controlMode.Value)
		{
		case TimeControlMode.MovementBased:
			ApplyVelocityBasedTime();
			break;
		case TimeControlMode.InputBased:
			ApplyInputBasedTime();
			break;
		}
	}

	private void ApplyVelocityBasedTime()
	{
		float magnitude = ((Vector2)(ref heroController.current_velocity)).magnitude;
		float unscaledDeltaTime = Time.unscaledDeltaTime;
		if (magnitude > 0f)
		{
			inputActiveTime += unscaledDeltaTime;
			inputInActiveTime = 0f;
			if (inputActiveTime > 1f)
			{
				inputActiveTime = 1f;
			}
			float num = inputActiveTime;
			index = Mathf.RoundToInt(num * 1000f);
			curve = sigmoidRise[index];
			Time.timeScale = curve * maxSpeedMultiplier.Value;
		}
		else
		{
			inputInActiveTime += unscaledDeltaTime;
			inputActiveTime = 0f;
			if (inputInActiveTime > 1f)
			{
				inputInActiveTime = 1f;
			}
			float num2 = inputInActiveTime;
			index = Mathf.RoundToInt(num2 * 1000f);
			curve = 1f - sigmoidFall[index];
			Time.timeScale = curve;
		}
		Time.timeScale = Math.Clamp(Time.timeScale, minSpeedMultiplier.Value, maxSpeedMultiplier.Value);
		Time.fixedDeltaTime = 0.02f * Time.timeScale;
	}

	private void ApplyInputBasedTime()
	{
		float unscaledDeltaTime = Time.unscaledDeltaTime;
		if (inputActive)
		{
			inputActiveTime += unscaledDeltaTime;
			inputInActiveTime = 0f;
			if (inputActiveTime > 1f)
			{
				inputActiveTime = 1f;
			}
			float num = inputActiveTime;
			index = Mathf.RoundToInt(num * 1000f);
			curve = sigmoidRise[index];
			Time.timeScale = curve * inputStrength * maxSpeedMultiplier.Value;
		}
		else
		{
			inputInActiveTime += unscaledDeltaTime;
			inputActiveTime = 0f;
			if (inputInActiveTime > 1f)
			{
				inputInActiveTime = 1f;
			}
			float num2 = inputInActiveTime;
			index = Mathf.RoundToInt(num2 * 1000f);
			curve = 1f - sigmoidFall[index];
			Time.timeScale = curve;
		}
		Time.timeScale = Math.Clamp(Time.timeScale, minSpeedMultiplier.Value, maxSpeedMultiplier.Value);
		Time.fixedDeltaTime = 0.02f * Time.timeScale;
	}

	private void OnDestroy()
	{
		SceneManager.activeSceneChanged -= OnSceneChanged;
		Time.timeScale = 1f;
		Time.fixedDeltaTime = 0.02f;
	}
}