Decompiled source of Full Auto v1.0.0

FullAuto.dll

Decompiled 2 months 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FullAuto")]
[assembly: AssemblyTitle("FullAuto")]
[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;
		}
	}
}
namespace FullAuto
{
	[BepInPlugin("Omniscye.FullAuto", "FullAuto", "1.0")]
	public class FullAuto : BaseUnityPlugin
	{
		internal static FullAuto Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}
namespace Empress.FullAuto
{
	[BepInPlugin("com.empress.fullauto", "FullAuto", "1.4.0")]
	public class FullAutoPlugin : BaseUnityPlugin
	{
		private ConfigEntry<float> cfgFireRate;

		private ConfigEntry<float> cfgDoubleTapThreshold;

		private ConfigEntry<float> cfgDoubleTapDebounce;

		private ConfigEntry<bool> cfgHoldToFire;

		private ConfigEntry<bool> cfgEnabled;

		private readonly Dictionary<int, float> nextFireTime = new Dictionary<int, float>();

		private readonly HashSet<int> fullAutoArmed = new HashSet<int>();

		private float lastTapTime = -10f;

		private int lastTapGun = 0;

		private float ignoreKeyUntil = -10f;

		private void Awake()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "");
			cfgFireRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FireRateShotsPerSecond", 25f, "");
			cfgDoubleTapThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DoubleTapThresholdSeconds", 0.3f, "");
			cfgDoubleTapDebounce = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DoubleTapDebounceSeconds", 0.2f, "");
			cfgHoldToFire = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HoldToFire", false, "");
			string text = "\r\n░██████████           ░██ ░██       ░███                  ░██               \r\n░██                   ░██ ░██      ░██░██                 ░██               \r\n░██        ░██    ░██ ░██ ░██     ░██  ░██  ░██    ░██ ░████████  ░███████  \r\n░█████████ ░██    ░██ ░██ ░██    ░█████████ ░██    ░██    ░██    ░██    ░██ \r\n░██        ░██    ░██ ░██ ░██    ░██    ░██ ░██    ░██    ░██    ░██    ░██ \r\n░██        ░██   ░███ ░██ ░██    ░██    ░██ ░██   ░███    ░██    ░██    ░██ \r\n░██         ░█████░██ ░██ ░██    ░██    ░██  ░█████░██     ░████  ░███████  \r\n                                                                            \r\n                                                                            \r\n                                                                            ";
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
			GameObject val = new GameObject("Empress_FullAuto_Host");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)52;
			val.AddComponent<FullAutoHandshakeRouter>();
		}

		private void Update()
		{
			if (cfgEnabled.Value && FullAutoHandshakeRouter.IsLevelReady())
			{
				if (Input.GetKeyDown((KeyCode)101) && Time.time >= ignoreKeyUntil)
				{
					TryHandleTap();
				}
				if (!cfgHoldToFire.Value || Input.GetKey((KeyCode)101))
				{
					TryFireTick();
				}
				CleanupDroppedGuns();
			}
		}

		private void TryHandleTap()
		{
			try
			{
				PhysGrabber instance = PhysGrabber.instance;
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				PhysGrabObject grabbedPhysGrabObject = instance.grabbedPhysGrabObject;
				if ((Object)(object)grabbedPhysGrabObject == (Object)null || !grabbedPhysGrabObject.grabbedLocal)
				{
					return;
				}
				ItemGun component = ((Component)grabbedPhysGrabObject).GetComponent<ItemGun>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				int instanceID = ((Object)component).GetInstanceID();
				float time = Time.time;
				if (instanceID == lastTapGun && time - lastTapTime <= cfgDoubleTapThreshold.Value)
				{
					if (fullAutoArmed.Contains(instanceID))
					{
						fullAutoArmed.Remove(instanceID);
						nextFireTime.Remove(instanceID);
					}
					else
					{
						fullAutoArmed.Add(instanceID);
						nextFireTime[instanceID] = 0f;
					}
					lastTapTime = -10f;
					lastTapGun = 0;
					ignoreKeyUntil = time + cfgDoubleTapDebounce.Value;
				}
				else
				{
					lastTapGun = instanceID;
					lastTapTime = time;
				}
			}
			catch
			{
			}
		}

		private void TryFireTick()
		{
			try
			{
				PhysGrabber instance = PhysGrabber.instance;
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				PhysGrabObject grabbedPhysGrabObject = instance.grabbedPhysGrabObject;
				if ((Object)(object)grabbedPhysGrabObject == (Object)null || !grabbedPhysGrabObject.grabbedLocal)
				{
					return;
				}
				ItemGun component = ((Component)grabbedPhysGrabObject).GetComponent<ItemGun>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				int instanceID = ((Object)component).GetInstanceID();
				if (!fullAutoArmed.Contains(instanceID))
				{
					return;
				}
				float time = Time.time;
				float num = 1f / Math.Max(0.0001f, cfgFireRate.Value);
				if (!nextFireTime.ContainsKey(instanceID))
				{
					nextFireTime[instanceID] = 0f;
				}
				if (time < nextFireTime[instanceID])
				{
					return;
				}
				ItemToggle component2 = ((Component)component).GetComponent<ItemToggle>();
				if ((Object)(object)component2 != (Object)null)
				{
					int num2 = SemiFunc.PhotonViewIDPlayerAvatarLocal();
					component2.ToggleItem(!component2.toggleState, num2);
				}
				else
				{
					try
					{
						component.Shoot();
					}
					catch
					{
					}
				}
				nextFireTime[instanceID] = time + num;
			}
			catch
			{
			}
		}

		private void CleanupDroppedGuns()
		{
			try
			{
				PhysGrabber instance = PhysGrabber.instance;
				if ((Object)(object)instance == (Object)null)
				{
					fullAutoArmed.Clear();
					nextFireTime.Clear();
					return;
				}
				PhysGrabObject grabbedPhysGrabObject = instance.grabbedPhysGrabObject;
				HashSet<int> hashSet = new HashSet<int>();
				if ((Object)(object)grabbedPhysGrabObject != (Object)null && grabbedPhysGrabObject.grabbedLocal)
				{
					ItemGun component = ((Component)grabbedPhysGrabObject).GetComponent<ItemGun>();
					if ((Object)(object)component != (Object)null)
					{
						hashSet.Add(((Object)component).GetInstanceID());
					}
				}
				List<int> list = new List<int>();
				foreach (int item in fullAutoArmed)
				{
					if (!hashSet.Contains(item))
					{
						list.Add(item);
					}
				}
				foreach (int item2 in list)
				{
					fullAutoArmed.Remove(item2);
					nextFireTime.Remove(item2);
				}
			}
			catch
			{
			}
		}
	}
	public class FullAutoHandshakeRouter : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		[CompilerGenerated]
		private sealed class <PerformHandshake>d__14 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public FullAutoHandshakeRouter <>4__this;

			private float <elapsed>5__1;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					_handshakeComplete = false;
					if (PhotonNetwork.IsMasterClient)
					{
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 1;
						return true;
					}
					PhotonNetwork.RaiseEvent((byte)71, (object)null, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)2
					}, SendOptions.SendReliable);
					<elapsed>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					_handshakeComplete = true;
					return false;
				case 2:
					<>1__state = -1;
					break;
				}
				if (!_handshakeComplete && <elapsed>5__1 < 5f)
				{
					<elapsed>5__1 += Time.deltaTime;
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				if (!_handshakeComplete)
				{
					_handshakeComplete = 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();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForLevelThenHandshake>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public FullAutoHandshakeRouter <>4__this;

			private float <t>5__1;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<t>5__1 = 0f;
					goto IL_0066;
				case 1:
					<>1__state = -1;
					goto IL_0066;
				case 2:
					{
						<>1__state = -1;
						break;
					}
					IL_0066:
					if (((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated) && <t>5__1 < 20f)
					{
						<t>5__1 += Time.deltaTime;
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					_levelReady = true;
					if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
					{
						<>2__current = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.PerformHandshake());
						<>1__state = 2;
						return true;
					}
					_handshakeComplete = true;
					break;
				}
				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 const byte EVENT_HANDSHAKE_REQUEST = 71;

		private const byte EVENT_HANDSHAKE_RESPONSE = 72;

		private static bool _levelReady;

		private static bool _handshakeComplete;

		private static string _loadedSceneName;

		private bool _callbackHooked;

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (_callbackHooked)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
			}
			_callbackHooked = false;
		}

		public override void OnJoinedRoom()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			EnsureCallbackHooked();
			_handshakeComplete = false;
			_levelReady = false;
			Scene activeScene = SceneManager.GetActiveScene();
			if (IsRealLevel(((Scene)(ref activeScene)).name))
			{
				((MonoBehaviour)this).StartCoroutine(WaitForLevelThenHandshake());
			}
		}

		public override void OnLeftRoom()
		{
			if (_callbackHooked)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbackHooked = false;
			}
			_levelReady = false;
			_handshakeComplete = false;
		}

		private void EnsureCallbackHooked()
		{
			if (!_callbackHooked)
			{
				PhotonNetwork.AddCallbackTarget((object)this);
				_callbackHooked = true;
			}
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode m)
		{
			_loadedSceneName = ((Scene)(ref s)).name ?? string.Empty;
			_levelReady = false;
			_handshakeComplete = false;
			EnsureCallbackHooked();
			if (IsRealLevel(_loadedSceneName))
			{
				((MonoBehaviour)this).StartCoroutine(WaitForLevelThenHandshake());
			}
		}

		private bool IsRealLevel(string sceneName)
		{
			if (string.IsNullOrEmpty(sceneName))
			{
				return false;
			}
			if (sceneName.IndexOf("Lobby", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			return true;
		}

		[IteratorStateMachine(typeof(<WaitForLevelThenHandshake>d__13))]
		private IEnumerator WaitForLevelThenHandshake()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForLevelThenHandshake>d__13(0)
			{
				<>4__this = this
			};
		}

		[IteratorStateMachine(typeof(<PerformHandshake>d__14))]
		private IEnumerator PerformHandshake()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PerformHandshake>d__14(0)
			{
				<>4__this = this
			};
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0034: Expected O, but got Unknown
			try
			{
				if (photonEvent.Code == 71)
				{
					if (PhotonNetwork.IsMasterClient)
					{
						PhotonNetwork.RaiseEvent((byte)72, (object)null, new RaiseEventOptions
						{
							Receivers = (ReceiverGroup)1
						}, SendOptions.SendReliable);
					}
				}
				else if (photonEvent.Code == 72)
				{
					_handshakeComplete = true;
				}
			}
			catch
			{
			}
		}

		public static bool IsLevelReady()
		{
			if (!PhotonNetwork.InRoom)
			{
				return _levelReady;
			}
			return _levelReady && _handshakeComplete;
		}
	}
}