Decompiled source of SpeedEffects v1.1.2

Mods/SpeedEffects.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using MelonLoader;
using RumbleModUI;
using RumbleModdingAPI;
using SpeedEffects;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(SEClass), "SpeedEffects", "1.1.2", "TacoSlayer36", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 255, 248, 231)]
[assembly: MelonAuthorColor(255, 255, 248, 231)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpeedEffects")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedEffects")]
[assembly: AssemblyTitle("SpeedEffects")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SpeedEffects;

public static class BuildInfo
{
	public const string ModName = "SpeedEffects";

	public const string ModVersion = "1.1.2";

	public const string Description = "Zoom";

	public const string Author = "TacoSlayer36";

	public const string Company = "";
}
public class SEClass : MelonMod
{
	private bool init = false;

	private string scene = "Loader";

	private GameObject recordingCameraGO;

	private Camera recordingCameraCAM;

	private RecordingCamera recordingCameraRC;

	private Rigidbody playerRB;

	private PlayerMovement playerM;

	private GameObject playerHeadGO;

	private Material speedLinesMaterial;

	private Material hmdSpeedLinesMaterial;

	private GameObject ddolObjects;

	private GameObject speedLinesOverlay;

	private GameObject hmdSpeedLinesOverlay;

	private bool overlayReferencesGot = false;

	private bool playerReferencesGot = false;

	private Mod Mod = new Mod();

	private bool doDynamicFOV = true;

	private float fovEffectMultiplier = 4f;

	private float interpolationSpeed = 0.24f;

	private float maxFOV = 130f;

	private bool doSpeedLines = true;

	private float speedLinesPowerMultiplier = 0.19f;

	private Vector4 speedLinesColor = Color.op_Implicit(Color.white);

	private bool trackSpeedLinesToVelocity = false;

	private bool includeUpwardSpeed = false;

	private bool hmdSpeedLines = true;

	private bool hideNotFacingVelocity = false;

	private float hmdSpeedLinesMultiplier = 2f;

	private bool isRainbow = false;

	private float rainbowHue = 0f;

	private float speed;

	private float fovVelocity = 0f;

	private float baseFOV = 90f;

	private float minimumSpeed = 6f;

	private bool airBias = false;

	public override void OnLateInitializeMelon()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Expected O, but got Unknown
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Expected O, but got Unknown
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Expected O, but got Unknown
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Expected O, but got Unknown
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Expected O, but got Unknown
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Expected O, but got Unknown
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Expected O, but got Unknown
		Calls.onMapInitialized += sceneReady;
		UI.instance.UI_Initialized += OnUIInit;
		Mod.ModName = "SpeedEffects";
		Mod.ModVersion = "1.1.2";
		Mod.SetFolder("SpeedEffects");
		Mod.AddDescription("Description", "", "Zoom", new Tags
		{
			IsSummary = true
		});
		Mod.AddToList("<#F63>Do Dynamic FOV", true, 0, "Set to enable the speed-based field of view", new Tags());
		Mod.AddToList("<#EA7>FOV Effect Multiplier", 5f, "The strength of the FOV effect\nCalculated as: (base FOV + meters per second * multiplier) - minimum speed", new Tags());
		Mod.AddToList("<#EA7>FOV Smoothing", 0.24f, "The speed at which the FOV interpolates to the target value", new Tags());
		Mod.AddToList("<#EA7>Max FOV", 145f, "The maximum FOV value possible", new Tags());
		Mod.AddToList("<#BB3>Do Speed Lines", true, 0, "Set to enable anime speed lines on your flatscreen (for clips/streaming)", new Tags());
		Mod.AddToList("<#AE7>Speed Lines Strength", 0.2f, "The strength of the speed lines", new Tags());
		Mod.AddToList("<#AE7>Speed Lines Color", "#FFFFFF", "The hex color code for the speed lines, or type \"Rainbow\"", new Tags());
		Mod.AddToList("<#DD8>Include Upward Speed", false, 0, "Set to allow moving upwards to trigger the effects", new Tags());
		Mod.AddToList("<#DD8>Minimum Speed", 5f, "The minimum speed required before the speed effects start their calculations", new Tags());
		Mod.AddToList("<#DD8>Air Bias", false, 0, "Set to reduce speed effects when you're grounded", new Tags());
		Mod.AddToList("<#E8F>Show Speed Lines In-Game", true, 0, "Set to show speed lines inside your VR view\n(FOV changes will still not be visible)", new Tags());
		Mod.AddToList("<#E8F>Track Speed Lines To Velocity", false, 0, "Set to rotate speed lines to the direction you're moving, rather than the direction you're facing\n<#F00>Speed lines that are tracked to velocity must at least be set to visible for VR", new Tags());
		Mod.AddToList("<#E8F>Hide Speed Lines When Not Facing Velocity", false, 0, "Set to fade out speed lines when you aren't facing in the direction you're moving enough", new Tags());
		Mod.AddToList("<#E8F>In-Game Multiplier", 5f, "How much more visible speed lines are in-game as opposed to your flatscreen\n(5x is roughly the same visibility for both)", new Tags());
		Mod.GetFromFile();
		Mod.ModSaved += Save;
		Save();
		if (Mods.findOwnMod("FlatLand", "1.0.0", false))
		{
			try
			{
				Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "FlatLand");
				if (assembly != null && (assembly.GetType("FlatLand.main")?.GetField("dontDisableGameObject", BindingFlags.Static | BindingFlags.Public))?.GetValue(null) is IList list)
				{
					list.Add("Speed Lines");
				}
			}
			catch
			{
				((MelonBase)this).LoggerInstance.Error("Failed to work with FlatLand; make sure you have FlatLand 1.8.2+");
			}
		}
		if (!Mods.findOwnMod("VoidLand", "1.0.0", false))
		{
			return;
		}
		try
		{
			Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "VoidLand");
			if (assembly2 != null && (assembly2.GetType("VoidLand.main")?.GetField("dontDisableGameObject", BindingFlags.Static | BindingFlags.Public))?.GetValue(null) is IList list2)
			{
				list2.Add("Speed Lines");
			}
		}
		catch
		{
			((MelonBase)this).LoggerInstance.Error("Failed to work with VoidLand; make sure you have VoidLand 1.3.0+");
		}
	}

	public void OnUIInit()
	{
		UI.instance.AddMod(Mod);
	}

	public void Save()
	{
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		doDynamicFOV = (bool)Mod.Settings[1].SavedValue;
		fovEffectMultiplier = (float)Mod.Settings[2].SavedValue;
		interpolationSpeed = (float)Mod.Settings[3].SavedValue;
		maxFOV = (float)Mod.Settings[4].SavedValue;
		doSpeedLines = (bool)Mod.Settings[5].SavedValue;
		speedLinesPowerMultiplier = (float)Mod.Settings[6].SavedValue;
		Color val = default(Color);
		speedLinesColor = Color.op_Implicit(ColorUtility.TryParseHtmlString((string)Mod.Settings[7].SavedValue, ref val) ? val : Color.white);
		if (((string)Mod.Settings[7].SavedValue).ToLower() == "rainbow")
		{
			isRainbow = true;
		}
		else
		{
			isRainbow = false;
		}
		includeUpwardSpeed = (bool)Mod.Settings[8].SavedValue;
		minimumSpeed = (float)Mod.Settings[9].SavedValue;
		airBias = (bool)Mod.Settings[10].SavedValue;
		hmdSpeedLines = (bool)Mod.Settings[11].SavedValue;
		trackSpeedLinesToVelocity = (bool)Mod.Settings[12].SavedValue;
		hideNotFacingVelocity = (bool)Mod.Settings[13].SavedValue;
		hmdSpeedLinesMultiplier = 1f / (float)Mod.Settings[14].SavedValue;
		setOverlaysActiveness();
		try
		{
			resetEffects();
		}
		catch
		{
		}
	}

	public override void OnUpdate()
	{
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		if (!init || !playerReferencesGot)
		{
			return;
		}
		float num = 0f;
		if (airBias && playerM.WasGrounded)
		{
			num = 6f;
		}
		Vector3 val;
		try
		{
			if (includeUpwardSpeed)
			{
				val = playerRB.velocity;
				speed = ((Vector3)(ref val)).magnitude;
			}
			else
			{
				val = new Vector3(playerRB.velocity.x, Mathf.Clamp(playerRB.velocity.y, float.MinValue, 0f) * 0.6f, playerRB.velocity.z);
				speed = ((Vector3)(ref val)).magnitude;
			}
			speed = Mathf.Clamp(speed - minimumSpeed - num, 0f, float.MaxValue);
		}
		catch
		{
		}
		try
		{
			baseFOV = recordingCameraRC.fovSlider.value;
		}
		catch
		{
		}
		if (doDynamicFOV)
		{
			try
			{
				float num2 = baseFOV + speed * fovEffectMultiplier;
				float fieldOfView = recordingCameraCAM.fieldOfView;
				float num3 = Mathf.SmoothDamp(fieldOfView, num2, ref fovVelocity, interpolationSpeed);
				float fieldOfView2 = Mathf.Clamp(num3, baseFOV, maxFOV);
				recordingCameraCAM.fieldOfView = fieldOfView2;
			}
			catch
			{
			}
		}
		if (!doSpeedLines && !hmdSpeedLines)
		{
			return;
		}
		hmdSpeedLinesOverlay.transform.position = playerHeadGO.transform.position;
		if (trackSpeedLinesToVelocity)
		{
			Transform transform = hmdSpeedLinesOverlay.transform;
			val = playerRB.velocity;
			transform.rotation = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.forward) * Quaternion.Euler(0f, -90f, 0f);
		}
		else
		{
			hmdSpeedLinesOverlay.transform.rotation = playerHeadGO.transform.rotation * Quaternion.Euler(0f, -90f, 0f);
		}
		if (isRainbow)
		{
			float num4 = Mathf.Lerp(2f / 3f, 5f, Mathf.InverseLerp(5f, 9f, speed));
			rainbowHue += Time.deltaTime * num4;
			if (rainbowHue > 1f)
			{
				rainbowHue -= 1f;
			}
			speedLinesColor = Color.op_Implicit(Color.HSVToRGB(rainbowHue, 1f, 1f));
		}
		try
		{
			updateSpeedLinesShader();
		}
		catch
		{
		}
	}

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		scene = sceneName;
		if (scene == "Gym" && !init)
		{
			init = true;
			getReferences();
			ddolObjects = Object.Instantiate<GameObject>(Calls.LoadAssetFromStream<GameObject>((MelonMod)(object)this, "SpeedEffects.assets.speedeffects", "Speed Lines"));
			((Object)ddolObjects).name = "Speed Lines";
			Object.DontDestroyOnLoad((Object)(object)ddolObjects);
			speedLinesOverlay = ((Component)ddolObjects.transform.GetChild(0)).gameObject;
			hmdSpeedLinesOverlay = ((Component)ddolObjects.transform.GetChild(1)).gameObject;
			speedLinesMaterial = ((Graphic)((Component)speedLinesOverlay.transform.GetChild(0)).GetComponent<Image>()).material;
			hmdSpeedLinesMaterial = ((Renderer)((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).GetComponent<MeshRenderer>()).material;
			speedLinesMaterial.SetFloat("_RenderSpace", 1f);
			if (trackSpeedLinesToVelocity)
			{
				((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).gameObject.layer = LayerMask.NameToLayer("default");
			}
			else
			{
				((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).gameObject.layer = LayerMask.NameToLayer("PlayerFade");
			}
		}
	}

	private void sceneReady()
	{
		if (init)
		{
			getReferences();
		}
		MelonCoroutines.Start(waitUntilOverlays());
	}

	public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
	{
		playerReferencesGot = false;
	}

	private void setOverlaysActiveness()
	{
		if ((Object)(object)speedLinesOverlay == (Object)null || (Object)(object)hmdSpeedLinesOverlay == (Object)null)
		{
			return;
		}
		overlayReferencesGot = true;
		if (trackSpeedLinesToVelocity)
		{
			speedLinesOverlay.SetActive(false);
			if (hmdSpeedLines && !doSpeedLines)
			{
				hmdSpeedLinesOverlay.SetActive(true);
				((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).gameObject.layer = LayerMask.NameToLayer("PlayerFade");
			}
			if (!hmdSpeedLines && !doSpeedLines)
			{
				hmdSpeedLinesOverlay.SetActive(false);
			}
			if (!hmdSpeedLines && doSpeedLines)
			{
				((MelonBase)this).LoggerInstance.Error("Speed lines that are tracked to velocity cannot only be visible on flatscreen");
				hmdSpeedLines = true;
				Mod.Settings[11].SavedValue = true;
				Mod.Settings[11].Value = true;
			}
			if (hmdSpeedLines && doSpeedLines)
			{
				hmdSpeedLinesOverlay.SetActive(true);
				((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).gameObject.layer = LayerMask.NameToLayer("Default");
			}
		}
		else
		{
			((Component)hmdSpeedLinesOverlay.transform.GetChild(0)).gameObject.layer = LayerMask.NameToLayer("PlayerFade");
			hmdSpeedLinesOverlay.SetActive(hmdSpeedLines);
			speedLinesOverlay.SetActive(doSpeedLines);
		}
	}

	private IEnumerator waitUntilOverlays()
	{
		int i = 0;
		overlayReferencesGot = false;
		while (true)
		{
			if (overlayReferencesGot)
			{
				yield break;
			}
			setOverlaysActiveness();
			if (i++ > 10)
			{
				break;
			}
			yield return (object)new WaitForSeconds(1f);
		}
		((MelonBase)this).LoggerInstance.Error("SpeedEffects: Overlays not found after 10 seconds, giving up.");
	}

	private void getReferences()
	{
		recordingCameraGO = GameObject.Find("RecordingCamera");
		recordingCameraCAM = recordingCameraGO.GetComponent<Camera>();
		recordingCameraRC = recordingCameraGO.GetComponent<RecordingCamera>();
		PlayerController controller = Singleton<PlayerManager>.Instance.localPlayer.Controller;
		playerRB = ((Component)((Component)controller).transform.GetChild(2)).GetComponent<Rigidbody>();
		playerM = ((Component)controller).GetComponent<PlayerMovement>();
		playerHeadGO = ((Component)((Component)controller).transform.GetChild(2).GetChild(0).GetChild(0)).gameObject;
		playerReferencesGot = true;
	}

	private void updateSpeedLinesShader()
	{
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Clamp(speed, 0.15f, 100f);
		setBothMaterials("_MaskScale", 1f / (num * speedLinesPowerMultiplier));
		if (hideNotFacingVelocity)
		{
			float toMax = 1f / (num * speedLinesPowerMultiplier * 3f);
			Vector3 val = playerRB.velocity;
			Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
			val = playerHeadGO.transform.forward;
			float from = Quaternion.Angle(val2, Quaternion.LookRotation(((Vector3)(ref val)).normalized));
			float from2 = Mathf.Clamp(Remap(from, 0f, 180f, 2f, 0f), 0f, 1f);
			float value = Remap(from2, 0f, 1f, 2f, toMax);
			setBothMaterials("_MaskScale", value);
		}
		setBothMaterials("_Colour", Color.op_Implicit(speedLinesColor));
	}

	private void setBothMaterials(string property, float value)
	{
		speedLinesMaterial.SetFloat(property, value);
		hmdSpeedLinesMaterial.SetFloat(property, value * hmdSpeedLinesMultiplier);
	}

	private void setBothMaterials(string property, Color value)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		speedLinesMaterial.SetColor(property, value);
		hmdSpeedLinesMaterial.SetColor(property, value);
	}

	private void resetEffects()
	{
		if (!doDynamicFOV)
		{
			recordingCameraCAM.fieldOfView = baseFOV;
		}
		if (!doSpeedLines && !hmdSpeedLines)
		{
			setBothMaterials("_MaskScale", 10f);
		}
	}

	public static float Remap(float from, float fromMin, float fromMax, float toMin, float toMax)
	{
		float num = from - fromMin;
		float num2 = fromMax - fromMin;
		float num3 = num / num2;
		float num4 = toMax - toMin;
		float num5 = num4 * num3;
		return num5 + toMin;
	}
}