Decompiled source of ShortRangeTeleporterGun v1.1.1

ShortRangeTeleporter.dll

Decompiled 9 months ago
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using LethalLib.Modules;
using ShortRangeTeleporter.Behaviours;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShortRangeTeleporter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShortRangeTeleporter")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d6bc8c34-9ca4-4964-ba9e-0c8891867f4f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ShortRangeTeleporter
{
	[BepInPlugin("poochymut.telegun", "Short Range Telegun", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "poochymut.telegun";

		private const string NAME = "Short Range Telegun";

		private const string VERSION = "1.1.1";

		public static Plugin instance;

		private void Awake()
		{
			instance = this;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "telegunmod");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Item val2 = val.LoadAsset<Item>("Assets/telegunmod/TelegunItem.asset");
			TeleforwardPlayerItem teleforwardPlayerItem = val2.spawnPrefab.AddComponent<TeleforwardPlayerItem>();
			((GrabbableObject)teleforwardPlayerItem).grabbable = true;
			((GrabbableObject)teleforwardPlayerItem).grabbableToEnemies = true;
			((GrabbableObject)teleforwardPlayerItem).itemProperties = val2;
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Utilities.FixMixerGroups(val2.spawnPrefab);
			TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
			val3.clearPreviousText = true;
			val3.displayText = "The Short Range Teleporter is great for navigating the facility with a employee on monitor.\n\n";
			Items.RegisterShopItem(val2, (TerminalNode)null, (TerminalNode)null, val3, 30);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Telegun mod");
		}
	}
}
namespace ShortRangeTeleporter.Behaviours
{
	internal class TeleforwardPlayerItem : PhysicsProp
	{
		private RaycastHit hit;

		public float teleportDistance = 5.5f;

		public AudioSource audioSouce;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).useCooldown = 6f;
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown)
			{
				((GrabbableObject)this).RequireCooldown();
				((MonoBehaviour)this).StartCoroutine(TeleportAfterDelay());
			}
		}

		private IEnumerator TeleportAfterDelay()
		{
			((GrabbableObject)this).playerHeldBy.beamUpParticle.Play();
			((GrabbableObject)this).playerHeldBy.enteringSpecialAnimation = true;
			((GrabbableObject)this).playerHeldBy.inSpecialInteractAnimation = true;
			((Collider)((GrabbableObject)this).playerHeldBy.thisController).enabled = false;
			MovementActions movement = ((GrabbableObject)this).playerHeldBy.playerActions.Movement;
			((MovementActions)(ref movement)).Disable();
			((GrabbableObject)this).playerHeldBy.UpdateSpecialAnimationValue(true, (short)15, 1.5f, false);
			GameObject audioPlayer = new GameObject("TempAudioPlayer");
			AudioSource audioSource = audioPlayer.AddComponent<AudioSource>();
			float stretchedPitch = 1.4285715f;
			audioSource.pitch = stretchedPitch;
			audioSource.PlayOneShot(((GrabbableObject)this).itemProperties.throwSFX, 0.75f);
			audioSource.time = 0f;
			yield return (object)new WaitForSeconds(0.25f);
			HUDManager.Instance.ShakeCamera((ScreenShakeType)2);
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.45f);
			yield return (object)new WaitForSeconds(0.3f);
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.4f);
			yield return (object)new WaitForSeconds(2f);
			Vector3 forwardDirection = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward;
			forwardDirection.y = 0f;
			Vector3 teleDest = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position + ((Vector3)(ref forwardDirection)).normalized * teleportDistance;
			teleDest.y = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position.y;
			if (CanTeleport(teleDest) && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				if (Object.op_Implicit((Object)(object)((GrabbableObject)this).playerHeldBy.redirectToEnemy))
				{
					((Component)((GrabbableObject)this).playerHeldBy.redirectToEnemy).transform.position = teleDest;
				}
				else
				{
					PerformTeleportation(teleDest);
					((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
					((GrabbableObject)this).playerHeldBy.beamOutBuildupParticle.Play();
				}
			}
			else if (CanTeleport(teleDest) && (Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null)
			{
				((Component)this).transform.position = teleDest;
			}
			else if (!CanTeleport(teleDest) && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
			{
				((GrabbableObject)this).playerHeldBy.DamagePlayer(8, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				HUDManager.Instance.DisplayStatusEffect("Teleport Destination Blocked!!");
				((MonoBehaviour)this).StartCoroutine(PlayDmgSparksSFX());
				Object.Destroy((Object)(object)audioPlayer);
			}
			((GrabbableObject)this).playerHeldBy.UpdateSpecialAnimationValue(false, (short)0, 0f, false);
			((Collider)((GrabbableObject)this).playerHeldBy.thisController).enabled = true;
			((GrabbableObject)this).playerHeldBy.enteringSpecialAnimation = false;
			((GrabbableObject)this).playerHeldBy.inSpecialInteractAnimation = false;
			movement = ((GrabbableObject)this).playerHeldBy.playerActions.Movement;
			((MovementActions)(ref movement)).Enable();
			SoundManager.Instance.PlayAudio1AtPositionServerRpc(teleDest, 3);
			yield return (object)new WaitForSeconds(0f);
			Object.Destroy((Object)(object)audioPlayer);
		}

		private bool CanTeleport(Vector3 checkHit)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			int num = -1;
			num &= -1025;
			num &= -2097153;
			num &= -17;
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && Physics.Raycast(checkHit, Vector3.down, ref hit, float.PositiveInfinity, num, (QueryTriggerInteraction)2) && Vector3.Dot(((RaycastHit)(ref hit)).normal, Vector3.down) < 0f)
			{
				float num2 = 20f;
				return Vector3.Distance(checkHit, ((RaycastHit)(ref hit)).point) <= num2;
			}
			return false;
		}

		private IEnumerator PlayDmgSparksSFX()
		{
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 1.2f);
			yield return (object)new WaitForSeconds(0.02f);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.7f);
			yield return (object)new WaitForSeconds(0.02f);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.9f);
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.6f);
			yield return (object)new WaitForSeconds(0.05f);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.6f);
			yield return (object)new WaitForSeconds(0.1f);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.6f);
			yield return (object)new WaitForSeconds(0.07f);
			((GrabbableObject)this).playerHeldBy.beamOutParticle.Play();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.pocketSFX, 0.6f);
		}

		private void PerformTeleportation(Vector3 teleDest)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).playerHeldBy.averageVelocity = 0f;
			((GrabbableObject)this).playerHeldBy.velocityLastFrame = Vector3.zero;
			((GrabbableObject)this).playerHeldBy.TeleportPlayer(teleDest, false, 0f, false, true);
			((GrabbableObject)this).UseItemBatteries();
			((GrabbableObject)this).UseItemBatteries();
			((GrabbableObject)this).UseItemBatteries();
			((Component)this).GetComponent<AudioSource>().PlayOneShot(((GrabbableObject)this).itemProperties.grabSFX, 0.6f);
		}
	}
}