Decompiled source of VisualBacktrack3D v1.0.0

Backtrack3D.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Backtrack3D")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Backtrack3D")]
[assembly: AssemblyTitle("Backtrack3D")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace VisualBacktrack
{
	public class BacktrackPoint3DVisual : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <Animate>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public BacktrackPoint3DVisual <>4__this;

			private MapBacktrackPoint <mapPoint>5__1;

			private bool <syncAnimation>5__2;

			private AnimationCurve <curve>5__3;

			private float <speed>5__4;

			private float <lerp>5__5;

			private float <scaleValue>5__6;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Animate>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<mapPoint>5__1 = null;
				<curve>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<mapPoint>5__1 = ((Component)<>4__this).GetComponent<MapBacktrackPoint>();
					<syncAnimation>5__2 = VisualBacktrackConfig.SyncAnimation.Value && (Object)(object)<mapPoint>5__1 != (Object)null;
					<curve>5__3 = (<syncAnimation>5__2 ? <mapPoint>5__1.curve : AnimationCurve.EaseInOut(0f, 0f, 1f, 1f));
					<speed>5__4 = (<syncAnimation>5__2 ? <mapPoint>5__1.speed : VisualBacktrackConfig.AnimationSpeed.Value);
					<lerp>5__5 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<lerp>5__5 < 1f)
				{
					<lerp>5__5 += Time.deltaTime * <speed>5__4;
					<scaleValue>5__6 = <curve>5__3.Evaluate(<lerp>5__5);
					<>4__this.sphereObject.transform.localScale = Vector3.one * <scaleValue>5__6 * <>4__this.targetScale;
					<>2__current = (object)new WaitForSeconds(0.05f);
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private GameObject sphereObject;

		private MeshRenderer sphereRenderer;

		private Coroutine animationCoroutine;

		public float targetScale = 0.35f;

		private void Awake()
		{
			//IL_003c: 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)
			//IL_008d: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			sphereObject = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)sphereObject).name = "BacktrackSphere3D";
			sphereObject.transform.SetParent((Transform)null, true);
			sphereObject.transform.localScale = Vector3.zero;
			Object.Destroy((Object)(object)sphereObject.GetComponent<Collider>());
			sphereRenderer = sphereObject.GetComponent<MeshRenderer>();
			if ((Object)(object)sphereRenderer != (Object)null)
			{
				Material val = new Material(Shader.Find("Standard"));
				Color value = VisualBacktrackConfig.BacktrackPointColor.Value;
				value.a = VisualBacktrackConfig.Opacity.Value;
				val.color = value;
				if (value.a < 1f)
				{
					val.SetFloat("_Mode", 3f);
					val.SetInt("_SrcBlend", 5);
					val.SetInt("_DstBlend", 10);
					val.SetInt("_ZWrite", 0);
					val.DisableKeyword("_ALPHATEST_ON");
					val.EnableKeyword("_ALPHABLEND_ON");
					val.DisableKeyword("_ALPHAPREMULTIPLY_ON");
					val.renderQueue = 3000;
				}
				((Renderer)sphereRenderer).material = val;
				((Renderer)sphereRenderer).shadowCastingMode = (ShadowCastingMode)(VisualBacktrackConfig.CastShadows.Value ? 1 : 0);
			}
		}

		public void Set3DPosition(Vector3 worldPos)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			if ((Object)(object)sphereObject != (Object)null)
			{
				sphereObject.transform.position = worldPos + new Vector3(0f, targetScale / 2f, 0f);
			}
		}

		public void TriggerAnimation()
		{
			if (animationCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(animationCoroutine);
			}
			animationCoroutine = ((MonoBehaviour)this).StartCoroutine(Animate());
		}

		[IteratorStateMachine(typeof(<Animate>d__7))]
		private IEnumerator Animate()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Animate>d__7(0)
			{
				<>4__this = this
			};
		}
	}
	[HarmonyPatch(typeof(MapBacktrackPoint), "Show")]
	public static class MapBacktrackPoint_Show_Patch
	{
		public static void Postfix(MapBacktrackPoint __instance, bool _sameLayer)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0058: 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)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			BacktrackPoint3DVisual component = ((Component)__instance).GetComponent<BacktrackPoint3DVisual>();
			if ((Object)(object)component != (Object)null)
			{
				if ((Object)(object)Map.Instance != (Object)null)
				{
					Vector3 position = ((Component)__instance).transform.position;
					Vector3 val = (position - Map.Instance.OverLayerParent.position) / Map.Instance.Scale;
					((Vector3)(ref val))..ctor(val.x, 0f, val.z);
					component.Set3DPosition(val);
				}
				component.TriggerAnimation();
			}
		}
	}
	public static class VisualBacktrackConfig
	{
		public static ConfigEntry<bool> CastShadows;

		public static ConfigEntry<Color> BacktrackPointColor;

		public static ConfigEntry<bool> SyncAnimation;

		public static ConfigEntry<float> AnimationSpeed;

		public static ConfigEntry<float> Opacity;

		public static void Initialize(ConfigFile config)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			CastShadows = config.Bind<bool>("3D Visuals", "CastShadows", true, "Should the 3D Backtrack points cast shadows?");
			BacktrackPointColor = config.Bind<Color>("3D Visuals", "BacktrackPointColor", Color.white, "Color of the 3D Backtrack points");
			SyncAnimation = config.Bind<bool>("3D Visuals", "SyncAnimation", true, "Sync animation with the map's 2D backtrack points?");
			AnimationSpeed = config.Bind<float>("3D Visuals", "AnimationSpeed", 1f, "Animation speed for 3D backtrack points if not in sync");
			Opacity = config.Bind<float>("3D Visuals", "Opacity", 0.75f, "Opacity (transparency) of the 3D backtrack points");
		}
	}
	[BepInPlugin("com.nilaier.visualbacktrack", "VisualBacktrackPlugin", "1.0.0")]
	public class VisualBacktrackPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(MapBacktrack), "Start")]
		public static class MapBacktrack_Start_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(MapBacktrack __instance)
			{
				MapBacktrackPoint[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<MapBacktrackPoint>(true);
				foreach (MapBacktrackPoint val in componentsInChildren)
				{
					if ((Object)(object)((Component)val).gameObject.GetComponent<BacktrackPoint3DVisual>() == (Object)null)
					{
						((Component)val).gameObject.AddComponent<BacktrackPoint3DVisual>();
					}
				}
			}
		}

		public const string PluginGuid = "com.nilaier.visualbacktrack";

		public const string PluginName = "VisualBacktrackPlugin";

		public const string PluginVersion = "1.0.0";

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			VisualBacktrackConfig.Initialize(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("com.nilaier.visualbacktrack");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"VisualBacktrackPlugin loaded.");
		}
	}
}