Decompiled source of PermaPings v1.0.0

BepInEx/plugins/PermaPings.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.UI;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("PermaPings")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PermaPings")]
[assembly: AssemblyTitle("PermaPings")]
[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 PermaPings
{
	internal static class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Update <0>__PlayerCharacterMasterController_Update;

			public static Action<Stage> <1>__ResetPings;

			public static hook_Update <2>__PingIndicator_Update;
		}

		public static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0053: 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_005e: Expected O, but got Unknown
			object obj = <>O.<0>__PlayerCharacterMasterController_Update;
			if (obj == null)
			{
				hook_Update val = PlayerCharacterMasterController_Update;
				<>O.<0>__PlayerCharacterMasterController_Update = val;
				obj = (object)val;
			}
			PlayerCharacterMasterController.Update += (hook_Update)obj;
			Stage.onServerStageComplete += PermaPingerController.ResetPings;
			object obj2 = <>O.<2>__PingIndicator_Update;
			if (obj2 == null)
			{
				hook_Update val2 = PingIndicator_Update;
				<>O.<2>__PingIndicator_Update = val2;
				obj2 = (object)val2;
			}
			PingIndicator.Update += (hook_Update)obj2;
		}

		private static void PingIndicator_Update(orig_Update orig, PingIndicator self)
		{
			if (!PermaPingerController.permapingsIndicators.Contains(self))
			{
				orig.Invoke(self);
			}
		}

		private static void PlayerCharacterMasterController_Update(orig_Update orig, PlayerCharacterMasterController self)
		{
			//IL_004f: 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_005f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (self.hasEffectiveAuthority && Object.op_Implicit((Object)(object)self.bodyInputs) && Object.op_Implicit((Object)(object)self.body))
			{
				KeyboardShortcut value = PermaPingsConfig.permaPingKey.Value;
				if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
				{
					PermaPingerController.AttemptPing(new Ray(self.bodyInputs.aimOrigin, self.bodyInputs.aimDirection), ((Component)self.body).gameObject, ((Component)self).gameObject);
				}
			}
		}
	}
	internal static class PermaPingerController
	{
		private static List<PingInfo> permapings = new List<PingInfo>();

		public static List<PingIndicator> permapingsIndicators = new List<PingIndicator>();

		public static void AttemptPing(Ray aimRay, GameObject bodyObject, GameObject owner)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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)
			PingInfo result = default(PingInfo);
			if (PingerController.GeneratePingInfo(aimRay, bodyObject, ref result) && (Object)(object)result.targetNetworkIdentity != (Object)null)
			{
				int num = permapings.FindIndex((PingInfo permaping) => (Object)(object)permaping.targetNetworkIdentity == (Object)(object)result.targetNetworkIdentity);
				if (num == -1)
				{
					permapings.Add(result);
					BuildPing(result, owner);
				}
				else
				{
					RemovePing(num);
				}
			}
		}

		private static void BuildPing(PingInfo pingInfo, GameObject owner)
		{
			//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_002e: 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_005d: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(LegacyResourcesAPI.Load<GameObject>("Prefabs/PingIndicator"));
			PingIndicator component = val.GetComponent<PingIndicator>();
			component.pingOwner = owner;
			component.pingOrigin = pingInfo.origin;
			component.pingNormal = pingInfo.normal;
			component.pingTarget = ((PingInfo)(ref pingInfo)).targetGameObject;
			component.RebuildPing();
			Transform transform = component.interactablePingGameObjects[0].transform;
			transform.localScale *= PermaPingsConfig.permaPingSize.Value / 100f;
			SpriteRenderer component2 = component.interactablePingGameObjects[0].GetComponent<SpriteRenderer>();
			Color color = (Color)(((??)GetItemColor(((PingInfo)(ref pingInfo)).targetGameObject)) ?? component2.color);
			color.a *= PermaPingsConfig.permaPingAlpha.Value / 100f;
			component2.color = color;
			TextMeshPro pingText = component.pingText;
			((TMP_Text)pingText).fontSize = ((TMP_Text)pingText).fontSize * (PermaPingsConfig.permaPingSize.Value / 100f);
			TextMeshPro pingText2 = component.pingText;
			((TMP_Text)pingText2).alpha = ((TMP_Text)pingText2).alpha * (PermaPingsConfig.permaPingAlpha.Value / 100f);
			permapingsIndicators.Add(component);
		}

		private static Color? GetItemColor(GameObject interactable)
		{
			//IL_003e: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (!PermaPingsConfig.permaPingItemTierColor.Value)
			{
				return null;
			}
			GenericPickupController component;
			if ((Object)(object)(component = interactable.GetComponent<GenericPickupController>()) != (Object)null)
			{
				return ((PickupIndex)(ref component.pickupIndex)).GetPickupColor();
			}
			PickupPickerController component2;
			if ((Object)(object)interactable.GetComponent<ScrapperController>() == (Object)null && (Object)(object)(component2 = interactable.GetComponent<PickupPickerController>()) != (Object)null && component2.options.Length != 0)
			{
				return ((PickupIndex)(ref component2.options[0].pickupIndex)).GetPickupColor();
			}
			ShopTerminalBehavior component3;
			if ((Object)(object)(component3 = interactable.GetComponent<ShopTerminalBehavior>()) != (Object)null)
			{
				PickupIndex val = component3.CurrentPickupIndex();
				return ((PickupIndex)(ref val)).GetPickupColor();
			}
			return null;
		}

		internal static void RemovePing(int index)
		{
			permapings.RemoveAt(index);
			if ((Object)(object)permapingsIndicators[index] != (Object)null && (Object)(object)((Component)permapingsIndicators[index]).gameObject != (Object)null)
			{
				PingIndicator obj = permapingsIndicators[index];
				Object.Destroy((Object)(object)((obj != null) ? ((Component)obj).gameObject : null));
			}
			permapingsIndicators.RemoveAt(index);
		}

		internal static void ResetPings(Stage stage)
		{
			permapings = new List<PingInfo>();
			permapingsIndicators = new List<PingIndicator>();
		}
	}
	[BepInPlugin("kyryh.permapings", "PermaPings", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class PermaPings : BaseUnityPlugin
	{
		public const string PluginGUID = "kyryh.permapings";

		public const string PluginName = "PermaPings";

		public const string PluginVersion = "1.0.0";

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			PermaPingsConfig.Init(((BaseUnityPlugin)this).Config);
			Hooks.Init();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin kyryh.permapings is loaded!");
		}

		public static void LogDebug(object data)
		{
			Log.LogDebug(data);
		}

		public static void LogError(object data)
		{
			Log.LogError(data);
		}
	}
	internal static class PermaPingsConfig
	{
		public static ConfigEntry<KeyboardShortcut> permaPingKey;

		public static ConfigEntry<float> permaPingAlpha;

		public static ConfigEntry<float> permaPingSize;

		public static ConfigEntry<bool> permaPingItemTierColor;

		public static void Init(ConfigFile config)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			permaPingKey = config.Bind<KeyboardShortcut>("Keybinds", "PermaPingButton", new KeyboardShortcut((KeyCode)326, Array.Empty<KeyCode>()), "Which key to use to place a permanent ping");
			permaPingAlpha = config.Bind<float>("Visuals", "PermaPingAlpha", 50f, "Alpha value of the perma-ping icon, i.e. how opaque it is\n100 means it's completely visible, 0 means it's completely transparent");
			permaPingSize = config.Bind<float>("Visuals", "PermaPingSize", 75f, "Size of the perma-ping icon and text");
			permaPingItemTierColor = config.Bind<bool>("Visuals", "PermaPingItemTierColor", true, "Whether to use the pinged item's tier as the ping's color");
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				AddConfigOptions();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void AddConfigOptions()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0016: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0041: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new KeyBindOption(permaPingKey));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(permaPingAlpha, new SliderConfig
			{
				min = 0f,
				max = 100f
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(permaPingSize, new SliderConfig
			{
				min = 0f,
				max = 100f
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(permaPingItemTierColor));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PermaPings";

		public const string PLUGIN_NAME = "PermaPings";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}