Decompiled source of ToggleTranqGunEffect v1.0.0

ToggleTranqGunEffect.dll

Decompiled a day 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("SEAL")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ToggleTranqGunEffect")]
[assembly: AssemblyTitle("ToggleTranqGunEffect")]
[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.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;
		}
	}
}
public class TranqSynchronizer : MonoBehaviourPun
{
	private bool remotePitchActive = false;

	[PunRPC]
	private void RPC_SyncVoicePitch(bool state)
	{
		remotePitchActive = state;
	}

	public void SyncVoicePitch(bool state)
	{
		if (((MonoBehaviourPun)this).photonView.IsMine)
		{
			((MonoBehaviourPun)this).photonView.RPC("RPC_SyncVoicePitch", (RpcTarget)1, new object[1] { state });
		}
	}

	private void Update()
	{
		if (remotePitchActive)
		{
			ApplyRemotePitch();
		}
	}

	private void ApplyRemotePitch()
	{
		Type type = Type.GetType("PlayerVoiceChat, Assembly-CSharp");
		if (type == null)
		{
			return;
		}
		Object[] array = Object.FindObjectsOfType(type);
		foreach (Object val in array)
		{
			Object obj = ((val is MonoBehaviour) ? val : null);
			PhotonView val2 = ((obj != null) ? ((Component)obj).GetComponent<PhotonView>() : null);
			if (!((Object)(object)val2 == (Object)null) && val2.Owner == ((MonoBehaviourPun)this).photonView.Owner)
			{
				type.GetMethod("OverridePitch", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(val, new object[6] { 0.65f, 1f, 1f, 3f, 0.1f, 20f });
				break;
			}
		}
	}
}
namespace ToggleTranqEffect
{
	[BepInPlugin("com.seal.toggletranq", "Toggle Tranq Effect", "1.0.0")]
	public class ToggleTranq : BaseUnityPlugin
	{
		public static ToggleTranq? Instance;

		private ConfigEntry<string>? keyString;

		private ConfigEntry<bool>? toggleMode;

		private KeyCode key = (KeyCode)116;

		public bool effectActive = false;

		private MonoBehaviour? playerAvatar;

		private MethodInfo? overridePupilMethod;

		private float searchTimer = 0f;

		private void Awake()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			keyString = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "ActivationKey", "T", new ConfigDescription("Tasto per attivare l'effetto tranq", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "G", "Z", "X", "V" }), Array.Empty<object>()));
			toggleMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "ToggleMode", true, "True = toggle, False = hold");
			if (!Enum.TryParse<KeyCode>(keyString.Value, ignoreCase: true, out key))
			{
				key = (KeyCode)116;
			}
			Harmony val = new Harmony("com.seal.toggletranq");
			val.PatchAll(typeof(EyesPatch));
			val.PatchAll(typeof(PlayerAvatarPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"╔═══════════════════════════════════════╗");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"║           TOGGLETRANQEFFECT           ║");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"╚═══════════════════════════════════════╝");
		}

		private void Update()
		{
			//IL_00c3: 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)
			if ((Object)(object)playerAvatar == (Object)null)
			{
				searchTimer += Time.deltaTime;
				if (searchTimer >= 1f)
				{
					searchTimer = 0f;
					FindPlayerAvatar();
				}
				return;
			}
			bool flag = effectActive;
			ConfigEntry<bool>? obj = toggleMode;
			if (obj != null && obj.Value)
			{
				if (Input.GetKeyDown(key))
				{
					effectActive = !effectActive;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83c\udfaf Tranq Toggle: " + (effectActive ? "ON" : "OFF")));
				}
			}
			else
			{
				effectActive = Input.GetKey(key);
			}
			if (flag != effectActive && SemiFunc.IsMultiplayer())
			{
				MonoBehaviour? obj2 = playerAvatar;
				TranqSynchronizer tranqSynchronizer = ((obj2 != null) ? ((Component)obj2).GetComponent<TranqSynchronizer>() : null);
				if ((Object)(object)tranqSynchronizer != (Object)null)
				{
					tranqSynchronizer.SyncVoicePitch(effectActive);
				}
			}
			if (effectActive)
			{
				ApplyEffects();
			}
		}

		private void FindPlayerAvatar()
		{
			try
			{
				Type type = Type.GetType("PlayerAvatar, Assembly-CSharp");
				if (type != null)
				{
					PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public);
					if (property != null)
					{
						ref MonoBehaviour? reference = ref playerAvatar;
						object? value = property.GetValue(null);
						reference = (MonoBehaviour?)((value is MonoBehaviour) ? value : null);
						if ((Object)(object)playerAvatar != (Object)null)
						{
							((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerAvatar.instance trovato");
							FindPupilMethod();
							return;
						}
					}
				}
				MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
				MonoBehaviour[] array2 = array;
				foreach (MonoBehaviour val in array2)
				{
					if (!((Object)(object)val == (Object)null) && !(((object)val).GetType().Name != "PlayerAvatar"))
					{
						FieldInfo field = ((object)val).GetType().GetField("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (field != null && (bool)field.GetValue(val))
						{
							playerAvatar = val;
							((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerAvatar trovato (manual)");
							FindPupilMethod();
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPlayerAvatar: " + ex.Message));
			}
		}

		private void FindPupilMethod()
		{
			try
			{
				if (!((Object)(object)playerAvatar == (Object)null))
				{
					overridePupilMethod = ((object)playerAvatar).GetType().GetMethod("OverridePupilSize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (overridePupilMethod != null)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ OverridePupilSize trovato");
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPupilMethod: " + ex.Message));
			}
		}

		private void ApplyEffects()
		{
			if ((Object)(object)PlayerVoiceChat.instance != (Object)null)
			{
				PlayerVoiceChat.instance.OverridePitch(0.65f, 1f, 1f, 3f, 0.1f, 20f);
			}
			if (overridePupilMethod != null && (Object)(object)playerAvatar != (Object)null)
			{
				try
				{
					overridePupilMethod.Invoke(playerAvatar, new object[7] { 3f, 4, 1f, 1f, 5f, 0.5f, 1.8f });
				}
				catch
				{
				}
			}
		}
	}
	[HarmonyPatch]
	internal class EyesPatch
	{
		private static MethodBase? TargetMethod()
		{
			return AccessTools.Method("PlayerEyes:Update", (Type[])null, (Type[])null);
		}

		private static void Postfix(MonoBehaviour __instance)
		{
			if ((Object)(object)ToggleTranq.Instance == (Object)null)
			{
				return;
			}
			try
			{
				FieldInfo field = ((object)__instance).GetType().GetField("pupilSizeMultiplier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					float num = (float)field.GetValue(__instance);
					float num2 = (ToggleTranq.Instance.effectActive ? 3f : 1f);
					float num3 = Mathf.Lerp(num, num2, Time.deltaTime * 2f);
					field.SetValue(__instance, num3);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar))]
	internal class PlayerAvatarPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void AddSynchronizer(PlayerAvatar __instance)
		{
			if (SemiFunc.IsMultiplayer())
			{
				PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
				if (!((Object)(object)component == (Object)null) && (Object)(object)((Component)__instance).GetComponent<TranqSynchronizer>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<TranqSynchronizer>();
				}
			}
		}
	}
}