Decompiled source of PingScan v0.1.4

plugins/com.github.yueby.PingScan.dll

Decompiled a month ago
using System;
using System.Diagnostics;
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 PingScan.Components;
using PingScan.Patches;
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("com.github.yueby.PingScan")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyProduct("com.github.yueby.PingScan")]
[assembly: AssemblyTitle("PingScan")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.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.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PingScan
{
	[BepInPlugin("com.github.yueby.PingScan", "PingScan", "0.1.4")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ConfigEntry<bool> configEnable;

		public const string Id = "com.github.yueby.PingScan";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "PingScan";

		public static string Version => "0.1.4";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			configEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable", true, "Enable the plugin");
			PointPingerPatches.InitializeConfig(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
}
namespace PingScan.Patches
{
	[HarmonyPatch(typeof(PointPinger))]
	public class PointPingerPatches
	{
		private static ConfigEntry<float> _configScanDuration;

		private static ConfigEntry<float> _configMaxScale;

		private static ConfigEntry<float> _configOpacity;

		private static ConfigEntry<float> _configDistanceOffset;

		public static void InitializeConfig(ConfigFile config)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			_configScanDuration = config.Bind<float>("General", "Duration", 0.6f, "Duration of scan animation in seconds");
			_configMaxScale = config.Bind<float>("General", "Max Scale", 15f, "Maximum scale of the ping sphere");
			_configOpacity = config.Bind<float>("General", "Opacity", 0.5f, new ConfigDescription("Opacity of the ping sphere", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			_configDistanceOffset = config.Bind<float>("General", "Distance Offset", 3f, "Distance offset for sphere scaling (higher values make sphere smaller near player)");
		}

		[HarmonyPatch("ReceivePoint_Rpc")]
		[HarmonyPrefix]
		private static void BeforeReceivePointPatch(PointPinger __instance, ref Vector3 __0, ref Vector3 __1)
		{
			//IL_000e: 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_0024: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.configEnable.Value)
			{
				Vector3 point = __0;
				Color playerColor = __instance.character.refs.customization.PlayerColor;
				CreatePingScan(point, playerColor);
			}
		}

		private static void CreatePingScan(Vector3 point, Color characterColor)
		{
			//IL_002c: 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)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			if ((Object)(object)val != (Object)null)
			{
				Collider component = val.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
				val.transform.position = point;
				PingScanning pingScanning = val.AddComponent<PingScanning>();
				pingScanning.Init(_configScanDuration.Value, _configMaxScale.Value, characterColor, _configOpacity.Value, _configDistanceOffset.Value);
			}
			else
			{
				Plugin.Log.LogError((object)"Failed to create sphere GameObject");
			}
		}
	}
}
namespace PingScan.Components
{
	public class PingScanning : MonoBehaviour
	{
		public float scanDuration = 0.6f;

		public float maxScale = 15f;

		private const float _fadeOutTime = 0.7f;

		private float _currentTime;

		private Vector3 _startScale;

		private Renderer _sphereRenderer;

		private float _initialOpacity;

		private float _distanceOffset;

		public void Init(float duration, float maxScaleValue, Color characterColor, float opacity, float distanceOffset)
		{
			//IL_0017: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0075: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			scanDuration = duration;
			maxScale = maxScaleValue;
			_distanceOffset = distanceOffset;
			_startScale = Vector3.one * 0.1f;
			((Component)this).transform.localScale = _startScale;
			_sphereRenderer = ((Component)this).GetComponent<Renderer>();
			if ((Object)(object)_sphereRenderer != (Object)null)
			{
				Material val = new Material(((Renderer)Character.localCharacter.refs.mainRenderer).sharedMaterial.shader);
				val.SetColor("_BaseColor", characterColor);
				val.SetFloat("_Opacity", opacity);
				_sphereRenderer.material = val;
				if ((Object)(object)val != (Object)null)
				{
					_initialOpacity = val.GetFloat("_Opacity");
				}
			}
		}

		private void Update()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_sphereRenderer))
			{
				return;
			}
			_currentTime += Time.deltaTime;
			float num = _currentTime / scanDuration;
			if (num <= 1f)
			{
				float num2 = Vector3.Distance(Character.localCharacter.Center, ((Component)this).transform.position);
				float num3 = Mathf.Min(maxScale, Mathf.Max(0f, num2 * 2f - _distanceOffset));
				float num4 = EaseOutExpo(num);
				((Component)this).transform.localScale = Vector3.Lerp(_startScale, Vector3.one * num3, num4);
				if (num >= 0.7f && (Object)(object)_sphereRenderer != (Object)null && (Object)(object)_sphereRenderer.material != (Object)null)
				{
					float num5 = (num - 0.7f) / 0.3f;
					float num6 = Mathf.Lerp(_initialOpacity, 0f, num5);
					_sphereRenderer.material.SetFloat("_Opacity", num6);
				}
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private float EaseOutExpo(float t)
		{
			if (t != 1f)
			{
				return 1f - Mathf.Pow(2f, -10f * t);
			}
			return 1f;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}