Decompiled source of SimpleTruckCompass v1.0.1

SimpleTruckCompass.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SimpleTruckCompass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Simple Truck Compass edge-tracking 3D pointer for REPO")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d1a0044f444e2e37f7131e43879ebce812c1e9b3")]
[assembly: AssemblyProduct("SimpleTruckCompass")]
[assembly: AssemblyTitle("SimpleTruckCompass")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SimpleTruckCompass
{
	[BepInPlugin("com.dan0dbfe.repo.simpletruckcompass", "Simple Truck Compass", "1.0.0")]
	public class SimpleTruckCompassPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.dan0dbfe.repo.simpletruckcompass";

		public const string PluginName = "Simple Truck Compass";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ConfigEnablePointer;

		internal static ConfigEntry<float> ConfigPointerSize;

		internal static ConfigEntry<string> ConfigPointerColor;

		internal static ConfigEntry<float> ConfigEdgePadding;

		private GameObject _pointerGo;

		private SpriteRenderer _pointerRenderer;

		private Camera _mapCamera;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigEnablePointer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePointer", true, "Enable the edge-tracking truck pointer on the map.");
			ConfigPointerSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PointerSize", 0.5f, "Size scale of the pointer sprite.");
			ConfigPointerColor = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PointerColor", "00FFEA", "Hex color code for the pointer.");
			ConfigEdgePadding = ((BaseUnityPlugin)this).Config.Bind<float>("General", "EdgePadding", 0.08f, "Padding from the edge of the screen (0.0 to 0.5).");
			Log.LogInfo((object)"Simple Truck Compass loaded successfully.");
		}

		private void LateUpdate()
		{
			if (!ConfigEnablePointer.Value)
			{
				if ((Object)(object)_pointerGo != (Object)null)
				{
					_pointerGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)Map.Instance == (Object)null || !Map.Instance.Active)
			{
				if ((Object)(object)_pointerGo != (Object)null)
				{
					_pointerGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)PlayerController.instance == (Object)null || (Object)(object)PlayerController.instance.playerAvatarScript == (Object)null)
			{
				if ((Object)(object)_pointerGo != (Object)null)
				{
					_pointerGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)TruckSafetySpawnPoint.instance == (Object)null)
			{
				if ((Object)(object)_pointerGo != (Object)null)
				{
					_pointerGo.SetActive(false);
				}
				return;
			}
			if (Traverse.Create((object)PlayerController.instance.playerAvatarScript.RoomVolumeCheck).Field("inTruck").GetValue<bool>())
			{
				if ((Object)(object)_pointerGo != (Object)null)
				{
					_pointerGo.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_mapCamera == (Object)null)
			{
				Camera[] source = Resources.FindObjectsOfTypeAll<Camera>();
				_mapCamera = ((IEnumerable<Camera>)source).FirstOrDefault((Func<Camera, bool>)((Camera c) => ((Object)c).name == "Dirt Finder Map Camera"));
				if ((Object)(object)_mapCamera == (Object)null)
				{
					if ((Object)(object)_pointerGo != (Object)null)
					{
						_pointerGo.SetActive(false);
					}
					return;
				}
			}
			EnsurePointerExists();
			_pointerGo.SetActive(true);
			UpdatePointerTransform();
		}

		private void EnsurePointerExists()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_pointerGo == (Object)null)
			{
				_pointerGo = new GameObject("TruckCompassPointer");
				_pointerGo.transform.SetParent(Map.Instance.OverLayerParent, false);
				_pointerRenderer = _pointerGo.AddComponent<SpriteRenderer>();
				_pointerRenderer.sprite = CreateTriangleSprite();
				((Renderer)_pointerRenderer).sortingOrder = 100;
				_pointerGo.layer = ((Component)Map.Instance.OverLayerParent).gameObject.layer;
			}
			Color color = Color.cyan;
			Color val = default(Color);
			if (ColorUtility.TryParseHtmlString("#" + ConfigPointerColor.Value.Trim('#'), ref val))
			{
				color = val;
			}
			_pointerRenderer.color = color;
			float value = ConfigPointerSize.Value;
			_pointerGo.transform.localScale = new Vector3(value, value, value);
		}

		private void UpdatePointerTransform()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_007c: 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)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)PlayerController.instance).transform.position;
			Vector3 position2 = ((Component)TruckSafetySpawnPoint.instance).transform.position;
			Vector3 val = position2 - position;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.1f))
			{
				Vector3 position3 = ((Component)_mapCamera).transform.position;
				position3.y = Map.Instance.OverLayerParent.position.y;
				Vector3 val2 = position3 + ((Vector3)(ref val)).normalized * 500f;
				Vector3 val3 = _mapCamera.WorldToViewportPoint(val2);
				float num = Mathf.Clamp(ConfigEdgePadding.Value, 0f, 0.5f);
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(0.5f, 0.5f);
				Vector2 val5 = new Vector2(val3.x, val3.y) - val4;
				Vector2 normalized = ((Vector2)(ref val5)).normalized;
				float num2 = Mathf.Abs(normalized.x);
				float num3 = Mathf.Abs(normalized.y);
				float num4 = 1f;
				if (num2 > num3 && num2 > 0.001f)
				{
					num4 = (0.5f - num) / num2;
				}
				else if (num3 > 0.001f)
				{
					num4 = (0.5f - num) / num3;
				}
				Vector2 val6 = val4 + normalized * num4;
				Vector3 position4 = _mapCamera.ViewportToWorldPoint(new Vector3(val6.x, val6.y, _mapCamera.nearClipPlane + 1f));
				position4.y = Map.Instance.OverLayerParent.position.y + 0.1f;
				_pointerGo.transform.position = position4;
				_pointerGo.transform.rotation = Quaternion.LookRotation(Vector3.up, val);
			}
		}

		private static Sprite CreateTriangleSprite()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			int num = 32;
			Texture2D val = new Texture2D(num, num, (TextureFormat)5, false);
			Color[] array = (Color[])(object)new Color[num * num];
			Vector2 a = default(Vector2);
			((Vector2)(ref a))..ctor((float)num / 2f, (float)(num - 1));
			Vector2 b = default(Vector2);
			((Vector2)(ref b))..ctor(1f, 1f);
			Vector2 c = default(Vector2);
			((Vector2)(ref c))..ctor((float)(num - 2), 1f);
			Vector2 p = default(Vector2);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					((Vector2)(ref p))..ctor((float)j, (float)i);
					int num2 = i * num + j;
					array[num2] = ((!IsPointInTriangle(p, a, b, c)) ? Color.clear : Color.white);
				}
			}
			val.SetPixels(array);
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
		}

		private static bool IsPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			double num = (p.x - b.x) * (a.y - b.y) - (a.x - b.x) * (p.y - b.y);
			double num2 = (p.x - c.x) * (b.y - c.y) - (b.x - c.x) * (p.y - c.y);
			double num3 = (p.x - a.x) * (c.y - a.y) - (c.x - a.x) * (p.y - a.y);
			if (num < 0.0 || num2 < 0.0 || num3 < 0.0)
			{
				if (!(num > 0.0) && !(num2 > 0.0))
				{
					return !(num3 > 0.0);
				}
				return false;
			}
			return true;
		}
	}
}