Decompiled source of FasterScanning v1.0.2

FasterScanning.dll

Decompiled 7 months 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 Gameplay.TacticalTargeting;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UI.Core;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.ModMessages;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FasterScanning")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("FasterScanning")]
[assembly: AssemblyTitle("FasterScanning")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 FasterScanning
{
	[BepInPlugin("FasterScanning", "FasterScanning", "1.0.2")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal class Bindings
		{
			internal const float VanillaDefaultValue = 2.5f;

			internal static ConfigEntry<float> ScanTimeMultiplier;

			internal static float ActiveValue;
		}

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Bindings.ScanTimeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScanTimeMultiplier", 0.15f, new ConfigDescription("The currently active Scan Time multiplier. The host's value is automatically sent to clients and can be changed during runtime.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			Bindings.ActiveValue = Bindings.ScanTimeMultiplier.Value * 2.5f;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FasterScanning is loaded!");
		}

		public static string GetActiveValueForDisplay()
		{
			return (Bindings.ActiveValue / 2.5f).ToString("0.0#x");
		}

		public static void UpdateActiveValue(float CAV)
		{
			Bindings.ActiveValue = CAV;
			Log.LogInfo((object)("Updating Active Value to " + CAV));
			if (KeybindDurationPatch.ScanTimeHI != null)
			{
				KeybindDurationPatch.ScanTimeHI.duration = CAV;
			}
			if (KeybindDurationPatch.KeyBindVEInstance != null)
			{
				UIPatch.DurationFI.SetValue(KeybindDurationPatch.KeyBindVEInstance, CAV);
			}
		}
	}
	internal class GUI : ModSettingsMenu
	{
		private string ScanMultiplierString = string.Empty;

		public override string Name()
		{
			return "Faster Scanning - " + BepinPlugin.GetActiveValueForDisplay();
		}

		public override void Draw()
		{
			if (Game.InGame && !PhotonNetwork.IsMasterClient)
			{
				GUILayout.Label("Must be host to configure. Current setting: " + BepinPlugin.GetActiveValueForDisplay(), Array.Empty<GUILayoutOption>());
				return;
			}
			GUILayout.Label("Scan Time Multiplier", Array.Empty<GUILayoutOption>());
			ScanMultiplierString = GUILayout.TextField(ScanMultiplierString, Array.Empty<GUILayoutOption>());
			if (float.TryParse(ScanMultiplierString, out var result) && result >= 0f && result <= 10f)
			{
				if (GUILayout.Button("Apply Setting - Current value: " + BepinPlugin.GetActiveValueForDisplay(), Array.Empty<GUILayoutOption>()))
				{
					BepinPlugin.Bindings.ScanTimeMultiplier.Value = result;
					BepinPlugin.UpdateActiveValue(result * 2.5f);
					UpdateActiveScanTimeMessage.Instance.SendToOthers();
				}
			}
			else
			{
				GUILayout.Label("Cannot Change Setting - Must be a number between 0 and 10.", Array.Empty<GUILayoutOption>());
			}
		}

		public override void OnOpen()
		{
			ScanMultiplierString = BepinPlugin.Bindings.ScanTimeMultiplier.Value.ToString();
		}
	}
	[HarmonyPatch(typeof(TacticalScan), "AbilityStarted")]
	internal class KeybindDurationPatch
	{
		private static FieldInfo stateFI = AccessTools.Field(typeof(InputActionMap), "m_State");

		internal static HoldInteraction ScanTimeHI;

		internal static KeyBindVE KeyBindVEInstance;

		private static void Postfix(TacticalScan __instance)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			InputAction action = ((InputActionAbility)__instance).InputAction.action;
			IInputInteraction[] interactions = ((InputActionState)stateFI.GetValue(action.actionMap)).interactions;
			foreach (IInputInteraction val in interactions)
			{
				HoldInteraction val2 = (HoldInteraction)(object)((val is HoldInteraction) ? val : null);
				if (val2 != null && val2.duration == 2.5f)
				{
					ScanTimeHI = val2;
					val2.duration = BepinPlugin.Bindings.ActiveValue;
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(KeyBindVE), "Init", new Type[]
	{
		typeof(InputAction),
		typeof(bool)
	})]
	internal class UIPatch
	{
		internal static FieldInfo DurationFI = AccessTools.Field(typeof(KeyBindVE), "duration");

		private static void Postfix(KeyBindVE __instance)
		{
			if ((float)DurationFI.GetValue(__instance) == 2.5f)
			{
				KeybindDurationPatch.KeyBindVEInstance = __instance;
				DurationFI.SetValue(__instance, BepinPlugin.Bindings.ActiveValue);
			}
		}
	}
	internal class UpdateActiveScanTimeMessage : ModMessage
	{
		internal static UpdateActiveScanTimeMessage Instance;

		public UpdateActiveScanTimeMessage()
		{
			Instance = this;
		}

		internal void SendToPlayer(Player player)
		{
			ModMessage.Send("FasterScanning", ((ModMessage)Instance).GetIdentifier(), player, new object[1] { BepinPlugin.Bindings.ActiveValue }, true);
		}

		internal void SendToOthers()
		{
			ModMessage.Send("FasterScanning", ((ModMessage)Instance).GetIdentifier(), MPModCheckManager.Instance.NetworkedPeersWithMod("FasterScanning").ToArray(), new object[1] { BepinPlugin.Bindings.ActiveValue }, true);
		}

		public override void Handle(object[] arguments, Player sender)
		{
			if (sender.IsMasterClient)
			{
				float cAV = (float)arguments[0];
				BepinPlugin.UpdateActiveValue(cAV);
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)4;

		public override string Author => "Dragon";

		public override string Description => "Reduces enemy scan time to 15% of vanilla scan time. Customizable, host and piloting client must have.";

		public VoidManagerPlugin()
		{
			Events.Instance.HostVerifiedClient += HostVerifiedClient;
			Events.Instance.JoinedRoom += ClientJoinSession;
			Events.Instance.HostStartSession += HostStartSession;
		}

		private static void HostVerifiedClient(object source, PlayerEventArgs Player)
		{
			if (MPModCheckManager.Instance.NetworkedPeerHasMod(Player.player, "FasterScanning"))
			{
				UpdateActiveScanTimeMessage.Instance.SendToPlayer(Player.player);
			}
		}

		private static void ClientJoinSession(object source, EventArgs ea)
		{
			BepinPlugin.UpdateActiveValue(2.5f);
		}

		private static void HostStartSession(object source, EventArgs ea)
		{
			BepinPlugin.UpdateActiveValue(BepinPlugin.Bindings.ScanTimeMultiplier.Value * 2.5f);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FasterScanning";

		public const string PLUGIN_NAME = "FasterScanning";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}