Decompiled source of velocityIndicator v1.0.0

Mods/velocityIndicator.dll

Decompiled 4 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using MelonLoader;
using RumbleModUI;
using RumbleModdingAPI;
using UnityEngine;
using UnityEngine.UI;
using velocityIndicator;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(main), "velocityIndicator", "1.0.0", "klibe", null)]
[assembly: VerifyLoaderVersion(0, 6, 2, true)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 240, 205, 53)]
[assembly: MelonAuthorColor(255, 240, 205, 53)]
[assembly: AssemblyTitle("velocityIndicator")]
[assembly: AssemblyDescription("Displays velocities, altitude, and other things.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5c49b9de-7b5c-4cdf-b63e-6dd388ff41ba")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace velocityIndicator;

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

	public const string ModVersion = "1.0.0";

	public const string Description = "Displays velocities, altitude, and other things.";

	public const string Author = "klibe";

	public const string Company = "";
}
public class Validation : ValidationParameters
{
	private int Length;

	public Validation(int i)
	{
		Length = i;
	}

	public override bool DoValidation(string Input)
	{
		if (Input.Length == Length)
		{
			return true;
		}
		return false;
	}
}
public class main : MelonMod
{
	private static GameObject velocityText;

	private static TextMeshPro velocityTextRef;

	private static GameObject structureVelocityText;

	private static TextMeshPro structureVelocityTextRef;

	private static GameObject flightText;

	private static TextMeshPro flightTextRef;

	private static float startY;

	private static bool prevGrounded;

	private static bool grounded;

	private static float flightTimer;

	private static float postFlightTime = 2f;

	private static float postFlightTimer = 0f;

	private static Color structureColor = new Color(1f, 0.8f, 0.2f);

	private static Color flightColor = new Color(0.65f, 0.85f, 1f);

	private static bool isInputReady = false;

	private static Rigidbody playerRef;

	private static PlayerMovement playerGroundedRef;

	private static float[] playerStats = new float[6];

	private static float prevPlayerSpeed = 0f;

	private static float playerMaxTimer = 0f;

	private static float playerMaxTime = 3f;

	private static float playerTotalSpeed = 0f;

	private static float playerTotalTime = 0f;

	private static Rigidbody followedStructure = null;

	private static float[] structureStats = new float[6];

	private static float prevStructureSpeed = 0f;

	private static float structureMaxTimer = 0f;

	private static float structureMaxTime = 3f;

	private static float structurePostDestroyTimer = 0f;

	private static float structurePostDestroyTime = 2f;

	private static float structureTotalTime = 0f;

	private static float structureTotalSpeed = 0f;

	private static bool isTrackingStructure = false;

	private static float[] emptyStats = new float[6];

	public static string currentScene = "Loader";

	public static bool prevInput = false;

	public static bool currentInput = false;

	public static Transform hand;

	public static int playerMode;

	public static int structureMode;

	public static int dataMode;

	public static bool useColors;

	public static int amountOfDecimals;

	public static string decstr;

	private static bool isMeasuringAcceleration;

	private Mod velocityIndicator = new Mod();

	public override void OnLateInitializeMelon()
	{
		Calls.onMapInitialized += initializeText;
		velocityIndicator.ModSaved += settingsSaved;
		UI.instance.UI_Initialized += OnUIInit;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		isInputReady = false;
		currentScene = sceneName;
	}

	public void settingsSaved()
	{
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		if ((bool)velocityIndicator.Settings[5].SavedValue)
		{
			structureMode = 0;
		}
		else if ((bool)velocityIndicator.Settings[6].SavedValue)
		{
			structureMode = 1;
		}
		else if ((bool)velocityIndicator.Settings[7].SavedValue)
		{
			structureMode = 2;
		}
		else
		{
			structureMode = 3;
		}
		if ((bool)velocityIndicator.Settings[9].SavedValue)
		{
			playerMode = 0;
		}
		else if ((bool)velocityIndicator.Settings[10].SavedValue)
		{
			playerMode = 1;
		}
		else if ((bool)velocityIndicator.Settings[11].SavedValue)
		{
			playerMode = 2;
		}
		else
		{
			playerMode = 3;
		}
		useColors = (bool)velocityIndicator.Settings[1].SavedValue;
		if (!useColors && (Object)(object)velocityTextRef != (Object)null)
		{
			((Graphic)velocityTextRef).color = Color.white;
		}
		amountOfDecimals = Mathf.Max((int)velocityIndicator.Settings[2].SavedValue, 0);
		isMeasuringAcceleration = (bool)velocityIndicator.Settings[3].SavedValue;
		dataMode = (int)velocityIndicator.Settings[4].SavedValue;
		decstr = "0";
		if (amountOfDecimals != 0)
		{
			decstr += ".";
			for (int i = 0; i < amountOfDecimals; i++)
			{
				decstr += "#";
			}
		}
		MelonLogger.Msg("Decimal String: " + decstr);
	}

	public void OnUIInit()
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Expected O, but got Unknown
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Expected O, but got Unknown
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Expected O, but got Unknown
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Expected O, but got Unknown
		velocityIndicator.ModName = "velocityIndicator";
		velocityIndicator.ModVersion = "1.0.0";
		velocityIndicator.SetFolder("Test");
		velocityIndicator.AddDescription("Description", "", "Displays velocities, altitude, and other things.", new Tags
		{
			IsSummary = true
		});
		velocityIndicator.AddToList("Enable colors", true, 0, "If the colors are too distracting, you can turn them off here.", new Tags());
		velocityIndicator.AddToList("Amount of decimals", 1, "Amount of decimal precision.", new Tags());
		velocityIndicator.AddToList("Change Speed for Acceleration", false, 0, "If true will display player and structure acceleration instead of speed.", new Tags());
		velocityIndicator.AddToList("Velocity Part", 0, "If 0, will display total velocity; if 1, will display upwards velocity, if 2; will display horizontal velocity.", new Tags());
		velocityIndicator.AddToList("Display Structure Current Speed", false, 1, "If true will display the current speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Display Structure Average Speed", false, 1, "If true will display the average speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Display Structure Top Speed", true, 1, "If true will display the top speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Hide Structure Statistics", false, 1, "If true will hide text showing structure speed.", new Tags());
		velocityIndicator.AddToList("Display Player Current Speed", true, 2, "If true will display the current speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Display Player Average Speed", false, 2, "If true will display the average speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Display Player Top Speed", false, 2, "If true will display the top speed of your tracked structure.", new Tags());
		velocityIndicator.AddToList("Hide Player Speed", false, 2, "If true will hide text showing player speed.", new Tags());
		settingsSaved();
		velocityIndicator.GetFromFile();
		UI.instance.AddMod(velocityIndicator);
		MelonLogger.Msg("Added Mod");
	}

	public void initializeText()
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		if (currentScene == "Gym" || currentScene == "Park")
		{
			hand = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).gameObject.transform.GetChild(1).GetChild(0).GetChild(0);
			velocityText = Create.NewText();
			((Object)velocityText).name = "Velocity Display";
			velocityText.transform.parent = Players.GetLocalHealthbarGameObject().transform.GetChild(1).GetChild(0);
			velocityText.transform.localPosition = new Vector3(-1.0564f, 0.0561f, 0.0907f);
			velocityText.transform.localRotation = Quaternion.Euler(62.9944f, 260f, 0f);
			velocityTextRef = velocityText.GetComponent<TextMeshPro>();
			((TMP_Text)velocityTextRef).text = "...";
			((TMP_Text)velocityTextRef).fontSize = 0.8f;
			((TMP_Text)velocityTextRef).enableWordWrapping = false;
			((Graphic)velocityTextRef).color = Color.white;
			structureVelocityText = Create.NewText();
			((Object)structureVelocityText).name = "Structure Velocity Display";
			structureVelocityText.transform.parent = Players.GetLocalHealthbarGameObject().transform.GetChild(1).GetChild(0);
			structureVelocityText.transform.localPosition = new Vector3(-1.0564f, 0.0761f, 0.0907f);
			structureVelocityText.transform.localRotation = Quaternion.Euler(62.9944f, 260f, 0f);
			structureVelocityTextRef = structureVelocityText.GetComponent<TextMeshPro>();
			((TMP_Text)structureVelocityTextRef).text = "";
			((TMP_Text)structureVelocityTextRef).fontSize = 0.6f;
			((TMP_Text)structureVelocityTextRef).enableWordWrapping = false;
			((Graphic)structureVelocityTextRef).color = structureColor;
			flightText = Create.NewText();
			((Object)flightText).name = "Altitude Display";
			flightText.transform.parent = Players.GetLocalHealthbarGameObject().transform.GetChild(1).GetChild(0);
			flightText.transform.localPosition = new Vector3(-1.0564f, 0.0961f, 0.0907f);
			flightText.transform.localRotation = Quaternion.Euler(62.9944f, 260f, 0f);
			flightTextRef = flightText.GetComponent<TextMeshPro>();
			((TMP_Text)flightTextRef).text = "";
			((TMP_Text)flightTextRef).fontSize = 0.6f;
			((TMP_Text)flightTextRef).m_textAlignment = (TextAlignmentOptions)514;
			((TMP_Text)flightTextRef).enableWordWrapping = false;
			((Graphic)flightTextRef).color = flightColor;
			playerRef = ((Component)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller).transform.GetChild(0)).GetComponent<Rigidbody>();
			playerGroundedRef = ((Component)((Component)playerRef).transform.parent.GetChild(3)).GetComponent<PlayerMovement>();
			isInputReady = true;
		}
	}

	public override void OnFixedUpdate()
	{
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		if (!isInputReady || (!(currentScene == "Gym") && !(currentScene == "Park")))
		{
			return;
		}
		prevGrounded = grounded;
		grounded = playerGroundedRef.IsGrounded();
		if (grounded != prevGrounded)
		{
			if (!grounded)
			{
				flightTimer = 0f;
				startY = ((Component)playerRef).transform.position.y;
				((TMP_Text)flightTextRef).text = "";
			}
			else
			{
				string text = "";
				int num = Mathf.FloorToInt(flightTimer / 60f);
				int num2 = Mathf.FloorToInt(flightTimer / 360f);
				text = ((num2 > 0) ? (num2 + ":" + num + ":" + flightTimer.ToString("0")) : ((num <= 0) ? flightTimer.ToString("0.##") : (num + ":" + flightTimer.ToString("0.##"))));
				((TMP_Text)flightTextRef).text = text;
			}
		}
		else if (!grounded)
		{
			((TMP_Text)flightTextRef).text = (((Component)playerRef).transform.position.y - startY).ToString(decstr) + " : " + flightTimer.ToString("0.##");
			flightTimer += Time.fixedDeltaTime;
		}
		else if (grounded)
		{
			postFlightTimer += Time.fixedDeltaTime;
			if (postFlightTimer >= postFlightTime)
			{
				flightTimer = 0f;
				((TMP_Text)flightTextRef).text = "";
			}
		}
		prevInput = currentInput;
		currentInput = RightController.GetGrip() > 0.8f && RightController.GetSecondary() == 1f;
		if (currentInput != prevInput && prevInput)
		{
			getPointedObject();
		}
		if ((Object)(object)followedStructure != (Object)null && !((Component)followedStructure).gameObject.active)
		{
			isTrackingStructure = false;
		}
		prevPlayerSpeed = playerStats[0];
		Vector3 velocity;
		if (dataMode == 2)
		{
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(playerRef.velocity.x, 0f, playerRef.velocity.z);
			playerStats[0] = ((Vector3)(ref val)).magnitude;
		}
		else if (dataMode == 1)
		{
			playerStats[0] = Mathf.Abs(playerRef.velocity.y);
		}
		else
		{
			float[] array = playerStats;
			velocity = playerRef.velocity;
			array[0] = ((Vector3)(ref velocity)).magnitude;
		}
		if (isTrackingStructure)
		{
			prevStructureSpeed = structureStats[0];
			if (dataMode == 2)
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(followedStructure.velocity.x, 0f, followedStructure.velocity.z);
				structureStats[0] = ((Vector3)(ref val2)).magnitude;
			}
			else if (dataMode == 1)
			{
				structureStats[0] = Mathf.Abs(followedStructure.velocity.y);
			}
			else
			{
				float[] array2 = structureStats;
				velocity = followedStructure.velocity;
				array2[0] = ((Vector3)(ref velocity)).magnitude;
			}
		}
		else
		{
			structureStats = emptyStats;
		}
		if (!isMeasuringAcceleration)
		{
			if (playerStats[0] > playerStats[2])
			{
				playerStats[2] = playerStats[0];
				playerMaxTimer = 0f;
			}
			else
			{
				playerMaxTimer += Time.fixedDeltaTime;
				if (playerMaxTimer > playerMaxTime)
				{
					playerStats[2] = playerStats[0];
				}
			}
			if (playerStats[0] > 0.4f && grounded)
			{
				playerTotalTime += Time.fixedDeltaTime;
				playerTotalSpeed += Time.fixedDeltaTime * playerStats[0];
				playerStats[1] = playerTotalSpeed / playerTotalTime;
			}
			else
			{
				playerTotalTime = 0f;
				playerTotalSpeed = 0f;
				playerStats[1] = 0f;
			}
			if (isTrackingStructure)
			{
				if (structureStats[0] > structureStats[2])
				{
					structureStats[2] = structureStats[0];
					structureMaxTimer = 0f;
				}
				else
				{
					structureMaxTimer += Time.fixedDeltaTime;
					if (structureMaxTimer > structureMaxTime)
					{
						structureStats[2] = structureStats[0];
					}
				}
				if (structureStats[0] > 0.2f)
				{
					structureTotalTime += Time.fixedDeltaTime;
					structureTotalSpeed += Time.fixedDeltaTime * structureStats[0];
					structureStats[1] = structureTotalSpeed / structureTotalTime;
				}
				else
				{
					structureTotalTime = 0f;
					structureTotalSpeed = 0f;
					structureStats[1] = 0f;
				}
			}
		}
		else
		{
			playerStats[3] = (playerStats[0] - prevPlayerSpeed) / Time.fixedDeltaTime;
			if (playerStats[3] > playerStats[5])
			{
				playerStats[5] = playerStats[3];
				playerMaxTimer = 0f;
			}
			else
			{
				playerMaxTimer += Time.fixedDeltaTime;
				if (playerMaxTimer > playerMaxTime)
				{
					playerStats[4] = playerStats[3];
				}
			}
			if (playerStats[3] == 0f)
			{
				playerTotalTime += Time.fixedDeltaTime;
				playerTotalSpeed += Time.fixedDeltaTime * playerStats[3];
				playerStats[4] = playerTotalSpeed / playerTotalTime;
			}
			else
			{
				playerTotalTime = 0f;
				playerTotalSpeed = 0f;
				playerStats[4] = 0f;
			}
			if (isTrackingStructure)
			{
				structureStats[3] = (structureStats[0] - prevStructureSpeed) / Time.fixedDeltaTime;
				if (structureStats[3] > structureStats[5])
				{
					structureStats[5] = structureStats[3];
					structureMaxTimer = 0f;
				}
				else
				{
					structureMaxTimer += Time.fixedDeltaTime;
					if (structureMaxTimer > structureMaxTime)
					{
						structureStats[5] = structureStats[3];
					}
				}
				if (structureStats[3] == 0.2f)
				{
					structureTotalTime += Time.fixedDeltaTime;
					structureTotalSpeed += Time.fixedDeltaTime * structureStats[0];
					structureStats[4] = structureTotalSpeed / structureTotalTime;
				}
				else
				{
					structureTotalTime = 0f;
					structureTotalSpeed = 0f;
					structureStats[4] = 0f;
				}
			}
		}
		displayPlayerInfo();
		displayStructureInfo();
	}

	public void getPointedObject()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		LayerMask val = LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "Move" }));
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(hand.position, hand.forward, ref val2, float.PositiveInfinity, LayerMask.op_Implicit(val)))
		{
			followedStructure = ((Component)((RaycastHit)(ref val2)).transform).gameObject.GetComponent<Rigidbody>();
			((TMP_Text)structureVelocityTextRef).text = "0";
			structureStats = emptyStats;
			structureTotalTime = 0f;
			structurePostDestroyTimer = 0f;
			isTrackingStructure = true;
		}
	}

	public void displayPlayerInfo()
	{
		//IL_003a: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		if (playerMode != 3)
		{
			if (useColors)
			{
				if (playerStats[playerMode] < 4f)
				{
					((Graphic)velocityTextRef).color = Color.green;
				}
				else if (playerStats[playerMode] < 10f)
				{
					((Graphic)velocityTextRef).color = Color.yellow;
				}
				else
				{
					((Graphic)velocityTextRef).color = Color.red;
				}
			}
			if (isMeasuringAcceleration)
			{
				((TMP_Text)velocityTextRef).text = playerStats[playerMode + 3].ToString(decstr);
			}
			else
			{
				((TMP_Text)velocityTextRef).text = playerStats[playerMode].ToString(decstr);
			}
		}
		else
		{
			((TMP_Text)velocityTextRef).text = "";
		}
	}

	public void displayStructureInfo()
	{
		if (structureMode != 3)
		{
			if (isTrackingStructure)
			{
				if (isMeasuringAcceleration)
				{
					((TMP_Text)structureVelocityTextRef).text = structureStats[structureMode + 3].ToString(decstr);
				}
				else
				{
					((TMP_Text)structureVelocityTextRef).text = structureStats[structureMode].ToString(decstr);
				}
				structurePostDestroyTimer = 0f;
				return;
			}
			structurePostDestroyTimer += Time.deltaTime;
			if (structurePostDestroyTimer >= structurePostDestroyTime)
			{
				structurePostDestroyTimer = 0f;
				((TMP_Text)structureVelocityTextRef).text = "";
			}
		}
		else
		{
			((TMP_Text)structureVelocityTextRef).text = "";
		}
	}
}