Decompiled source of Woodz Warper v1.1.2

woodzwarper.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
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 Reptile;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("woodzwarper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Seamless Teleport")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("woodzwarper")]
[assembly: AssemblyTitle("woodzwarper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 woodzwarper
{
	[BepInPlugin("info.mariobluegloves.warperp", "Warper", "0.0.1")]
	[BepInProcess("Bomb Rush Cyberfunk.exe")]
	public class WarperPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Teleport), "DoTeleport")]
		private class DoTeleportPatch
		{
			private static bool Prefix(Player player, Teleport __instance)
			{
				if (player.isAI)
				{
					player.CompletelyStop();
					__instance.PlacePlayer(player);
					if ((Object)(object)__instance.letAIGoToThisWaypointInstead != (Object)null)
					{
						player.AI.SetNextWaypointClean(__instance.letAIGoToThisWaypointInstead);
						return false;
					}
					if (__instance.letAIGoToTheNextWaypoint)
					{
						player.AI.SkipToNextTarget();
						return false;
					}
				}
				else if (__instance.teleportRoutine == null && lastTeleportTime >= warpCooldown.Value)
				{
					if (__instance.doDamage)
					{
						player.PlayVoice((AudioClipID)485, (VoicePriority)3, true);
					}
					if (__instance.automaticallyReturnPlayerToLastSafeLocation)
					{
						__instance.fadeToBlackDuration = __instance.fadeToBlackDurationDeathzone;
						__instance.blackDuration = __instance.blackDurationDeathzone;
						__instance.fadeOpenDuration = __instance.fadeOpenDurationDeathzone;
					}
					else
					{
						__instance.fadeToBlackDuration = __instance.fadeToBlackDurationDoor;
						__instance.blackDuration = __instance.blackDurationDoor;
						__instance.fadeOpenDuration = __instance.fadeOpenDurationDoor;
					}
					if (!instantDeathPlane.Value)
					{
						if (__instance.doDamage)
						{
							__instance.teleportRoutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.TeleportRoutine(player));
						}
						else
						{
							__instance.teleportRoutine = ((MonoBehaviour)__instance).StartCoroutine(WoodzTeleportRoutine(__instance, player));
						}
					}
					else
					{
						__instance.teleportRoutine = ((MonoBehaviour)__instance).StartCoroutine(WoodzTeleportRoutine(__instance, player));
					}
					lastTeleportTime = 0f;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Teleport), "PlacePlayer")]
		private class Patch_PlacePlayer
		{
			private static bool Prefix(Player player, Teleport __instance)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: 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_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: 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_004b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Invalid comparison between Unknown and I4
				//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0369: Unknown result type (might be due to invalid IL or missing references)
				//IL_036e: Unknown result type (might be due to invalid IL or missing references)
				//IL_037f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0321: Unknown result type (might be due to invalid IL or missing references)
				//IL_0326: Unknown result type (might be due to invalid IL or missing references)
				//IL_032a: Unknown result type (might be due to invalid IL or missing references)
				//IL_032f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0341: Unknown result type (might be due to invalid IL or missing references)
				//IL_0298: Unknown result type (might be due to invalid IL or missing references)
				//IL_029d: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0255: Unknown result type (might be due to invalid IL or missing references)
				//IL_0259: Unknown result type (might be due to invalid IL or missing references)
				//IL_025e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0270: Unknown result type (might be due to invalid IL or missing references)
				Rigidbody component = ((Component)player).GetComponent<Rigidbody>();
				lastSpeed = component.velocity;
				if (__instance.automaticallyReturnPlayerToLastSafeLocation && player.GetSafeLocation().timeStamp != -1f)
				{
					SafeLocation safeLocation = player.GetSafeLocation();
					WorldHandler.instance.PlacePlayerAt(player, safeLocation.position, safeLocation.rotation, false);
				}
				else if (WorldHandler.instance.currentEncounter is CombatEncounter && (int)WorldHandler.instance.currentEncounter.state == 4 && (Object)(object)WorldHandler.instance.currentEncounter.startSpawner != (Object)null)
				{
					WorldHandler.instance.PlacePlayerAt(player, WorldHandler.instance.currentEncounter.startSpawner, false);
				}
				else if ((Object)(object)__instance.teleportTo == (Object)null)
				{
					WorldHandler.instance.PlacePlayerAt(player, ((Component)__instance).transform.GetChild(0), false);
				}
				else if ((Object)(object)((Component)__instance.teleportTo).GetComponent<Teleport>() == (Object)null)
				{
					WorldHandler.instance.PlacePlayerAt(player, __instance.teleportTo, false);
				}
				else
				{
					WorldHandler.instance.PlacePlayerAt(player, __instance.teleportTo.GetChild(0), false);
				}
				if (player.IsGrounded())
				{
				}
				if (__instance.giveSpeedAtSpawn)
				{
				}
				if (player.grindAbility != null)
				{
					((Ability)player.airTrickAbility).p.StopCurrentAbility();
				}
				if (player.wallrunAbility != null)
				{
					((Ability)player.wallrunAbility).p.StopCurrentAbility();
				}
				Vector3 forward;
				if (!instantDeathPlane.Value)
				{
					if (__instance.doDamage)
					{
						player.GetHit(2, Vector3.zero, (KnockbackType)4);
						if (player.HP > 0f)
						{
							player.ActivateAbility((Ability)(object)player.recoverAbility);
						}
					}
					else if ((Object)(object)__instance.teleportTo != (Object)null && (Object)(object)((Component)__instance.teleportTo).GetComponent<Teleport>() == (Object)null && (((Object)__instance.teleportTo).name == "ExitSpawner" || ((Object)__instance.teleportTo).name == "Spawner"))
					{
						forward = __instance.teleportTo.forward;
						Vector3 normalized = ((Vector3)(ref forward)).normalized;
						DelayedVelocitySetter delayedVelocitySetter = ((Component)player).gameObject.AddComponent<DelayedVelocitySetter>();
						delayedVelocitySetter.Init(component, normalized, ((Vector3)(ref lastSpeed)).magnitude);
					}
					else
					{
						DelayedVelocitySetter delayedVelocitySetter2 = ((Component)player).gameObject.AddComponent<DelayedVelocitySetter>();
						Vector3 normalized2 = ((Vector3)(ref lastSpeed)).normalized;
						float magnitude = ((Vector3)(ref lastSpeed)).magnitude;
						delayedVelocitySetter2.Init(component, normalized2, magnitude);
					}
				}
				else if ((Object)(object)__instance.teleportTo != (Object)null && (Object)(object)((Component)__instance.teleportTo).GetComponent<Teleport>() == (Object)null && (((Object)__instance.teleportTo).name == "ExitSpawner" || ((Object)__instance.teleportTo).name == "Spawner"))
				{
					forward = __instance.teleportTo.forward;
					Vector3 normalized3 = ((Vector3)(ref forward)).normalized;
					DelayedVelocitySetter delayedVelocitySetter3 = ((Component)player).gameObject.AddComponent<DelayedVelocitySetter>();
					delayedVelocitySetter3.Init(component, normalized3, ((Vector3)(ref lastSpeed)).magnitude);
				}
				else
				{
					DelayedVelocitySetter delayedVelocitySetter4 = ((Component)player).gameObject.AddComponent<DelayedVelocitySetter>();
					Vector3 normalized4 = ((Vector3)(ref lastSpeed)).normalized;
					float magnitude2 = ((Vector3)(ref lastSpeed)).magnitude;
					delayedVelocitySetter4.Init(component, normalized4, magnitude2);
				}
				player.RemoveAllCuffs((CuffMissileLauncher)null);
				return false;
			}
		}

		private class PlayerTriggerHandler : MonoBehaviour
		{
			private WarperPlugin plugin;

			private Transform warpto;

			private Transform warpfrom;

			private Vector3 positionDifference;

			private Quaternion rotationDifference;

			public void Initialize(WarperPlugin plugin, Transform warpto, Transform warpfrom)
			{
				//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_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_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: 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_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: 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_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				this.plugin = plugin;
				this.warpto = warpto;
				this.warpfrom = warpfrom;
				Vector3 position = warpto.position;
				Quaternion rotation = warpto.rotation;
				Vector3 position2 = warpfrom.position;
				Quaternion rotation2 = warpfrom.rotation;
				positionDifference = position - position2;
				rotationDifference = rotation * Quaternion.Inverse(rotation2);
				Vector3 val = positionDifference;
				Debug.Log((object)("Position Difference: " + ((object)(Vector3)(ref val)).ToString()));
				Quaternion val2 = rotationDifference;
				Debug.Log((object)("Rotation Difference: " + ((object)(Quaternion)(ref val2)).ToString()));
			}

			private void OnTriggerEnter(Collider other)
			{
				if (((Object)((Component)other).gameObject).name == "seamlesswarp")
				{
					ApplyWarp();
				}
				if (((Object)((Component)other).gameObject).name == "seamlesswarp2")
				{
					ApplyWarp2();
				}
			}

			private void ApplyWarp()
			{
				//IL_000f: 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)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: 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)
				Player componentInParent = ((Component)((Component)this).transform).GetComponentInParent<Player>();
				componentInParent.SetRotation(rotationDifference * ((Component)this).transform.rotation);
				((Component)this).transform.position = warpto.position + rotationDifference * (((Component)this).transform.position - warpfrom.position);
			}

			private void ApplyWarp2()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: 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_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//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_005c: 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)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				Player componentInParent = ((Component)((Component)this).transform).GetComponentInParent<Player>();
				componentInParent.SetRotation(Quaternion.Inverse(rotationDifference) * ((Component)this).transform.rotation);
				((Component)this).transform.position = warpfrom.position + Quaternion.Inverse(rotationDifference) * (((Component)this).transform.position - warpto.position);
			}
		}

		private static ConfigEntry<bool> instantVanilla;

		private static ConfigEntry<bool> instantDeathPlane;

		public static ConfigEntry<float> warpCooldown;

		private Transform warpto;

		private Transform warpfrom;

		private bool sceneLoaded = false;

		private Vector3 positionDifference;

		private Quaternion rotationDifference;

		private Vector3 positionDifference2;

		private Quaternion rotationDifference2;

		public static Vector3 lastSpeed = Vector3.zero;

		public static float lastTeleportTime = 0f;

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			instantVanilla = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "InstantVanillaWarp", true, "Makes vanilla teleports instant, not break combos, and retain speed");
			Harmony val = new Harmony("info.mariobluegloves.warperpp");
			SceneManager.sceneLoaded += OnSceneLoaded;
			if (instantVanilla.Value)
			{
				val.PatchAll();
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			sceneLoaded = true;
		}

		private void Update()
		{
			instantDeathPlane = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "InstantDeathPlane", false, "Makes death warps not break combos and retain speed");
			warpCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WarpCooldown", 1f, "Time after last teleporting to allow teleporting again");
			lastTeleportTime += Time.deltaTime;
			if (lastTeleportTime >= 100f)
			{
				lastTeleportTime = 90f;
			}
			if (sceneLoaded)
			{
				GameObject val = GameObject.Find("Player_HUMAN0");
				GameObject obj = GameObject.Find("WarpTo");
				warpto = ((obj != null) ? obj.transform : null);
				GameObject obj2 = GameObject.Find("WarpFrom");
				warpfrom = ((obj2 != null) ? obj2.transform : null);
				if ((Object)(object)warpto != (Object)null && (Object)(object)warpfrom != (Object)null && (Object)(object)val != (Object)null)
				{
					PlayerTriggerHandler playerTriggerHandler = val.AddComponent<PlayerTriggerHandler>();
					playerTriggerHandler.Initialize(this, warpto, warpfrom);
					sceneLoaded = false;
				}
			}
		}

		private static IEnumerator WoodzTeleportRoutine(Teleport instance, Player player)
		{
			bool inEncounter = (Object)(object)WorldHandler.instance.currentEncounter != (Object)null;
			bool isInTransition = Teleport.IsInSequenceOrTransition();
			if (instance.automaticallyReturnPlayerToLastSafeLocation && inEncounter && isInTransition)
			{
				instance.teleportRoutine = null;
				yield break;
			}
			if (isInTransition)
			{
				while (Teleport.IsInSequenceOrTransition())
				{
					yield return null;
				}
			}
			instance.PlacePlayer(player);
			instance.teleportRoutine = null;
		}
	}
	public class DelayedVelocitySetter : MonoBehaviour
	{
		private Rigidbody rb;

		private Vector3 direction;

		private float speed;

		private float timer = 0f;

		private float delay = 0.05f;

		public void Init(Rigidbody rb, Vector3 direction, float speed)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			this.rb = rb;
			this.direction = direction;
			this.speed = speed;
		}

		private void Update()
		{
			//IL_0041: 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)
			timer += Time.deltaTime;
			if (timer >= delay)
			{
				if ((Object)(object)rb != (Object)null)
				{
					rb.velocity = direction * speed;
				}
				Object.Destroy((Object)(object)this);
			}
		}
	}
}