Decompiled source of SpeedMeter v0.2.0

mods/MelonLoaderModTest.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Beetle_Utils;
using Il2Cpp;
using MelonLoader;
using MelonLoaderModTest;
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: MelonInfo(typeof(Core), "MelonLoaderModTest", "1.0.0", "pablops", null)]
[assembly: MelonGame("Bugfight Studio", "Beetleball")]
[assembly: MelonAdditionalDependencies(new string[] { "BeetleUtils" })]
[assembly: MelonAdditionalCredits("Spike")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MelonLoaderModTest")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MelonLoaderModTest")]
[assembly: AssemblyTitle("MelonLoaderModTest")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MelonLoaderModTest
{
	public class Core : MelonMod
	{
		private static bool showSpeed;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}

		public override void OnUpdate()
		{
			if (Input.GetKeyDown((KeyCode)285))
			{
				if (showSpeed)
				{
					showSpeed = false;
				}
				else
				{
					showSpeed = true;
				}
			}
		}

		public override void OnGUI()
		{
			BeetleActor localBeetle = BeetleUtils.GetLocalBeetle();
			if ((Object)(object)localBeetle != (Object)null && showSpeed)
			{
				DrawSpeed();
			}
		}

		private void DrawSpeed()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			BeetleActor localBeetle = BeetleUtils.GetLocalBeetle();
			Vector3 velocity = localBeetle.Velocity;
			string text = ((Vector3)(ref velocity)).magnitude.ToString("0.00");
			GUI.Label(new Rect(20f, 20f, 1000f, 200f), "<b><color=cyan><size=40>Speed:" + text + "</size></color></b>");
		}
	}
}

mods/SpeedMeterMod.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Beetle_Utils;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using SpeedMeterMod;
using UnityEngine;
using UnityEngine.SceneManagement;
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(Core), "SpeedMeterMod", "1.0.0", "pablops", null)]
[assembly: MelonGame("Bugfight Studio", "Beetleball")]
[assembly: MelonAdditionalDependencies(new string[] { "BeetleUtils" })]
[assembly: MelonAdditionalCredits("Spike")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SpeedMeterMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedMeterMod")]
[assembly: AssemblyTitle("SpeedMeterMod")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SpeedMeterMod
{
	public class Core : MelonMod
	{
		private static bool showSpeedMeter;

		private static BeetleActor localBeetle;

		private static Texture speedmeterTX;

		private static Texture needleTX;

		private RawImage speedmeterImage;

		private RawImage needleImage;

		private GameObject speedmeterGO;

		private GameObject needleGO;

		private float currentAngle;

		private float needleSmooth = 5f;

		private const float MIN_ANGLE = 120f;

		private const float MAX_ANGLE = -120f;

		private const float MAX_SPEED = 240f;

		private Transform hudRoot;

		public override void OnInitializeMelon()
		{
			speedmeterTX = (Texture)(object)LoadTexture("speedmeter.png");
			needleTX = (Texture)(object)LoadTexture("needle.png");
			if ((Object)(object)speedmeterTX == (Object)null || (Object)(object)needleTX == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Msg("Failed to load all textures.");
			}
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}

		public override void OnUpdate()
		{
			UpdateLocalBeetle();
			HandleInput();
			UpdateSpeedometer();
		}

		private void HandleInput()
		{
			if (Input.GetKeyDown((KeyCode)285))
			{
				ToggleSpeedometer();
			}
		}

		private void ToggleSpeedometer()
		{
			if ((Object)(object)speedmeterGO == (Object)null)
			{
				((MelonBase)this).LoggerInstance.Msg("Creating Speedometer HUD elements.");
				FindHudRoot();
				CreateSpeedmeterInHud();
				CreateNeedleInHud(speedmeterGO.transform);
			}
			if (!showSpeedMeter)
			{
				((MelonBase)this).LoggerInstance.Msg("Speedometer on.");
				speedmeterGO.SetActive(true);
				showSpeedMeter = true;
			}
			else
			{
				((MelonBase)this).LoggerInstance.Msg("Speedometer off.");
				speedmeterGO.SetActive(false);
				showSpeedMeter = false;
			}
		}

		private void UpdateLocalBeetle()
		{
			BeetleActor val = BeetleUtils.GetLocalBeetle();
			if ((Object)(object)val != (Object)null)
			{
				localBeetle = val;
			}
		}

		private void CreateSpeedmeterInHud()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0070: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			speedmeterGO = new GameObject("Speedometer");
			speedmeterGO.transform.SetParent(hudRoot, false);
			speedmeterImage = speedmeterGO.AddComponent<RawImage>();
			speedmeterImage.texture = (Texture)(object)LoadTexture("speedmeter.png");
			RectTransform rectTransform = ((Graphic)speedmeterImage).rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rectTransform.anchorMax = val;
			rectTransform.anchorMin = val;
			rectTransform.pivot = new Vector2(0f, 1f);
			rectTransform.sizeDelta = new Vector2(200f, 165f);
			rectTransform.anchoredPosition = new Vector2(20f, -20f);
		}

		private void CreateNeedleInHud(Transform speedmeter)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			needleGO = new GameObject("Needle");
			needleGO.transform.SetParent(speedmeter, false);
			needleImage = needleGO.AddComponent<RawImage>();
			needleImage.texture = (Texture)(object)LoadTexture("needle.png");
			RectTransform rectTransform = ((Graphic)needleImage).rectTransform;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val;
			rectTransform.anchorMin = val;
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.sizeDelta = new Vector2(10f, 90f);
			rectTransform.anchoredPosition = new Vector2(0f, (0f - rectTransform.sizeDelta.y) * 0.2f);
			((Transform)rectTransform).localEulerAngles = new Vector3(0f, 0f, 120f);
			((Transform)rectTransform).SetAsLastSibling();
		}

		private void UpdateNeedle()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = localBeetle.Velocity;
			float num = ((Vector3)(ref velocity)).magnitude;
			float num2 = Mathf.InverseLerp(0f, 240f, num);
			float num3 = Mathf.Lerp(120f, -120f, num2);
			currentAngle = Mathf.Lerp(currentAngle, num3, Time.deltaTime * needleSmooth);
			((Transform)((Graphic)needleImage).rectTransform).localEulerAngles = new Vector3(0f, 0f, currentAngle);
		}

		private void UpdateSpeedometer()
		{
			if (!((Object)(object)localBeetle == (Object)null) && !((Object)(object)needleImage == (Object)null))
			{
				UpdateNeedle();
			}
		}

		private Texture2D LoadTexture(string fileName)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			string path = BeetleUtils.ModFolder();
			path = Path.Combine(path, "Assets");
			string text = Path.Combine(path, fileName);
			if (!File.Exists(text))
			{
				MelonLogger.Error("Texture not found: " + text);
				return null;
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
			return val;
		}

		private void FindHudRoot()
		{
			Il2CppArrayBase<Canvas> val = Object.FindObjectsOfType<Canvas>();
			foreach (Canvas item in val)
			{
				if (!(((Object)item).name == "Canvas"))
				{
					continue;
				}
				Transform val2 = ((Component)item).transform.Find("PlayerHUD");
				if ((Object)(object)val2 != (Object)null)
				{
					hudRoot = val2.Find("Root");
					if ((Object)(object)hudRoot != (Object)null)
					{
						MelonLogger.Msg("HUD Root found");
						break;
					}
				}
			}
		}

		private string DumpUnityTree()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(7, 1, stringBuilder2);
				handler.AppendLiteral("Scene: ");
				handler.AppendFormatted(((Scene)(ref sceneAt)).name);
				stringBuilder2.AppendLine(ref handler);
				foreach (GameObject item in (Il2CppArrayBase<GameObject>)(object)((Scene)(ref sceneAt)).GetRootGameObjects())
				{
					DumpTransform(item.transform, 1);
				}
			}
			return stringBuilder.ToString();
		}

		private void DumpTransform(Transform t, int depth)
		{
			string text = new string(' ', depth * 2);
			MelonLogger.Msg(text + "- " + ((Object)t).name);
			int childCount = t.childCount;
			for (int i = 0; i < childCount; i++)
			{
				Transform child = t.GetChild(i);
				DumpTransform(child, depth + 1);
			}
		}
	}
}