Decompiled source of Compass v1.0.1

Mods/LethalCompanyCompass.dll

Decompiled a year ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using LethalCompanyCompass;
using MelonLoader;
using TMPro;
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: AssemblyTitle("LethalCompanyCompass")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("LethalCompanyCompass")]
[assembly: AssemblyCopyright("Created by squidypal")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(global::LethalCompanyCompass.LethalCompanyCompass), "LethalCompanyCompass", "1.0.0", "squidypal", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalCompanyCompass;

public static class BuildInfo
{
	public const string Name = "LethalCompanyCompass";

	public const string Author = "squidypal";

	public const string Company = null;

	public const string Version = "1.0.0";

	public const string DownloadLink = null;
}
public class LethalCompanyCompass : MelonMod
{
	private GameObject player;

	private GameObject textGameObject;

	private TextMeshProUGUI textMesh;

	private float fadeDuration = 1f;

	private bool isFadingIn;

	private bool fade = false;

	public override void OnSceneWasInitialized(int buildIndex, string sceneName)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Expected O, but got Unknown
		if (!(sceneName == "MainMenu") && !(sceneName == "InitScene") && !(sceneName == "InitSceneLaunchOptions"))
		{
			player = ((Component)StartOfRound.Instance.localPlayerController).gameObject;
			if ((Object)(object)textGameObject == (Object)null)
			{
				textGameObject = new GameObject("TextMeshPro Object");
			}
			if ((Object)(object)textMesh == (Object)null)
			{
				textMesh = textGameObject.AddComponent<TextMeshProUGUI>();
			}
			((TMP_Text)textMesh).text = "Your Text Here";
			((TMP_Text)textMesh).fontSize = 36f;
			textGameObject.transform.SetParent(GameObject.Find("Systems/UI/Canvas").transform, false);
			((Object)textGameObject.transform).name = "Compass Text";
			textGameObject.transform.localPosition = new Vector3(-340f, 210f, 0f);
			((Graphic)textMesh).color = new Color(0.87f, 0.43f, 0.12f);
			((Graphic)textMesh).material = new Material(Shader.Find("TextMeshPro/Distance Field"));
		}
	}

	private string GetDirection(float yRotation)
	{
		yRotation = (yRotation + 360f) % 360f;
		if (yRotation <= 30f || yRotation > 330f)
		{
			return "North";
		}
		if (yRotation <= 60f)
		{
			return "North East";
		}
		if (yRotation <= 120f)
		{
			return "East";
		}
		if (yRotation <= 150f)
		{
			return "South East";
		}
		if (yRotation <= 210f)
		{
			return "South";
		}
		if (yRotation <= 240f)
		{
			return "South West";
		}
		if (yRotation <= 300f)
		{
			return "West";
		}
		return "North West";
	}

	public override void OnUpdate()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null)
		{
			if (!fade || ((Graphic)textMesh).color.a > 0f)
			{
				TriggerFade(fadeIn: false);
			}
			return;
		}
		if (((Graphic)textMesh).color.a < 1f)
		{
			TriggerFade(fadeIn: true);
		}
		Quaternion rotation = player.transform.rotation;
		float y = ((Quaternion)(ref rotation)).eulerAngles.y;
		string direction = GetDirection(y);
		((TMP_Text)textGameObject.GetComponent<TextMeshProUGUI>()).text = direction;
	}

	public void TriggerFade(bool fadeIn)
	{
		isFadingIn = fadeIn;
		MelonCoroutines.Start(FadeText());
	}

	private IEnumerator FadeText()
	{
		fade = true;
		float targetAlpha = (isFadingIn ? 1f : 0f);
		Color currentColor = ((Graphic)textMesh).color;
		float startAlpha = currentColor.a;
		for (float t = 0f; t < 1f; t += Time.deltaTime / fadeDuration)
		{
			Color newColor = new Color(currentColor.r, currentColor.g, currentColor.b, Mathf.Lerp(startAlpha, targetAlpha, t));
			((Graphic)textMesh).color = newColor;
			yield return null;
		}
		((Graphic)textMesh).color = new Color(currentColor.r, currentColor.g, currentColor.b, targetAlpha);
		fade = false;
	}
}