Decompiled source of FlightMod v1.1.5

FlightMod.dll

Decompiled 3 months ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Mirror;
using MoveClasses;
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: AssemblyTitle("FlightMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FlightMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2c822ce0-4e1d-4167-b3eb-245993c74c20")]
[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")]
[BepInPlugin("com.yourname.flight", "Flight mod", "1.1.4")]
[DisallowMultipleComponent]
public class FlightMod : BaseUnityPlugin
{
	private void Awake()
	{
		((Object)Chainloader.ManagerObject).hideFlags = (HideFlags)61;
		Harmony.CreateAndPatchAll(typeof(FlightMod), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"AWAKE: Hooking into SceneManager.sceneLoaded");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[FlightMod] OnSceneLoaded: {((Scene)(ref scene)).name}, mode={mode}, time={Time.realtimeSinceStartup}");
		((MonoBehaviour)this).StartCoroutine(DelayedSetup());
	}

	public IEnumerator DelayedSetup()
	{
		yield return (object)new WaitForSecondsRealtime(2f);
		Hand[] hands = Object.FindObjectsByType<Hand>((FindObjectsSortMode)0);
		if (hands == null)
		{
			yield break;
		}
		Hand[] array = hands;
		foreach (Hand hand in array)
		{
			if ((Object)(object)((Component)((Component)hand).transform.parent).gameObject.GetComponent<FlightController>() == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Hand found by Flight Mod " + ((Object)((Component)hand).gameObject).name));
				((Component)((Component)hand).transform.parent).gameObject.AddComponent<FlightController>();
			}
		}
	}
}
public class FlightController : MonoBehaviour
{
	private PlayerHealth character;

	private Rigidbody[] bodyParts;

	private GameObject Hip;

	private Hand hand;

	private Coroutine FlightLoopInstance;

	private Coroutine FlightMode;

	private Coroutine Punishhh;

	private Coroutine Genesis;

	private Vector3 startingHandPosition;

	private GameObject rapier;

	private List<HandState> stateHistory = new List<HandState>();

	private void Start()
	{
		character = ((Component)this).GetComponentInParent<PlayerHealth>();
		if ((Object)(object)character == (Object)null)
		{
			Debug.LogError((object)"Flight script requires a PlayerHealth on the Character!");
			Object.Destroy((Object)(object)this);
			return;
		}
		bodyParts = ((Component)character).GetComponentsInChildren<Rigidbody>();
		Rigidbody[] array = bodyParts;
		foreach (Rigidbody val in array)
		{
			if (((Object)((Component)val).gameObject).name == "HIP")
			{
				Hip = ((Component)val).gameObject;
			}
		}
		if ((Object)(object)Hip == (Object)null)
		{
			Debug.LogError((object)"Flight script didnt find the Hips!!!!");
			Object.Destroy((Object)(object)this);
			return;
		}
		hand = ((Component)this).GetComponentInChildren<Hand>();
		if ((Object)(object)hand != (Object)null && (Object)(object)character != (Object)null && !((Object)((Component)this).gameObject).name.ToLower().Contains("elbow"))
		{
			Debug.Log((object)("Starting Flight Coroutine " + ((Object)((Component)this).gameObject).name));
			if (FlightLoopInstance != null)
			{
				((MonoBehaviour)this).StopCoroutine(FlightLoopInstance);
			}
			FlightLoopInstance = ((MonoBehaviour)this).StartCoroutine(FlightLoop());
		}
	}

	private IEnumerator FlightLoop()
	{
		yield return (object)new WaitForEndOfFrame();
		Debug.Log((object)"Starting Flight Listener");
		HandState previousState = hand.handState;
		while ((Object)(object)character != (Object)null)
		{
			HandState currentState = hand.handState;
			if (currentState != previousState)
			{
				stateHistory.Add(currentState);
				if (stateHistory.Count > 8)
				{
					stateHistory.RemoveAt(0);
				}
				if (stateHistory.Count == 8)
				{
					if ((int)stateHistory[0] == 2 && (int)stateHistory[1] == 1 && (int)stateHistory[2] == 0 && (int)stateHistory[3] == 2 && (int)stateHistory[4] == 1 && (int)stateHistory[5] == 0 && (int)stateHistory[6] == 1 && (int)stateHistory[7] == 2)
					{
						if (FlightMode != null)
						{
							((MonoBehaviour)this).StopCoroutine(FlightMode);
						}
						FlightMode = ((MonoBehaviour)this).StartCoroutine(ActivateFlight(hand));
						stateHistory.Clear();
					}
					if (stateHistory.Count >= 8 && (int)stateHistory[0] == 2 && (int)stateHistory[1] == 1 && (int)stateHistory[2] == 2 && (int)stateHistory[3] == 0 && (int)stateHistory[4] == 1 && (int)stateHistory[5] == 0 && (int)stateHistory[6] == 1 && (int)stateHistory[7] == 2)
					{
						if (Genesis != null)
						{
							((MonoBehaviour)this).StopCoroutine(Genesis);
						}
						Genesis = ((MonoBehaviour)this).StartCoroutine(DestroyTheWorld(hand));
						stateHistory.Clear();
					}
					if (stateHistory.Count >= 8 && (int)stateHistory[0] == 2 && (int)stateHistory[1] == 1 && (int)stateHistory[2] == 2 && (int)stateHistory[3] == 1 && (int)stateHistory[4] == 2 && (int)stateHistory[5] == 1 && (int)stateHistory[6] == 0 && (int)stateHistory[7] == 2)
					{
						if (Punishhh != null)
						{
							((MonoBehaviour)this).StopCoroutine(Punishhh);
						}
						Punishhh = ((MonoBehaviour)this).StartCoroutine(ActivatePunishment(hand));
						stateHistory.Clear();
					}
				}
				previousState = currentState;
			}
			else
			{
				stateHistory.Clear();
			}
			yield return (object)new WaitForSeconds(0.25f);
		}
	}

	private IEnumerator ActivatePunishment(Hand hand)
	{
		Debug.Log((object)"You're getting punished...");
		Rigidbody[] HiddenRigidbodies = Resources.FindObjectsOfTypeAll<Rigidbody>();
		Rigidbody[] array = HiddenRigidbodies;
		foreach (Rigidbody rb in array)
		{
			if (((Component)rb).gameObject.layer == LayerMask.NameToLayer("Weapons") && (Object)(object)((Component)rb).GetComponent<Weapon>() != (Object)null && ((Object)((Component)rb).gameObject).name == "Rapier")
			{
				rapier = ((Component)rb).gameObject;
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
			}
		}
		Vector3 forward = -((Component)this).transform.up;
		Vector3 origin = ((Component)this).transform.position + forward * 1.5f;
		Vector3 capsuleStart = origin;
		Vector3 capsuleEnd = origin + forward * 4f;
		float radius = 1f;
		Collider[] hits = Physics.OverlapCapsule(capsuleStart, capsuleEnd, radius);
		Collider[] array2 = hits;
		foreach (Collider hit in array2)
		{
			Rigidbody rb2 = hit.attachedRigidbody;
			if ((Object)(object)rb2 == (Object)null || (Object)(object)((Component)this).GetComponentInParent<PlayerHealth>() == (Object)(object)((Component)hit).gameObject.GetComponentInParent<PlayerHealth>() || hit.isTrigger)
			{
				continue;
			}
			PlayerHealth playerhealth = ((Component)hit).gameObject.GetComponentInParent<PlayerHealth>();
			if ((Object)(object)playerhealth == (Object)null)
			{
				continue;
			}
			PlayerHealth castingPlayer = ((Component)hand).GetComponentInParent<PlayerHealth>();
			if (castingPlayer.playerName != "M4GMaR" && castingPlayer.playerName != "Player 1" && castingPlayer.playerName != "INSANE KING")
			{
				Debug.Log((object)"You dont have the power of the gods...");
				break;
			}
			Rigidbody[] rigidbodies = ((Component)playerhealth).GetComponentsInChildren<Rigidbody>();
			GameObject enemyHip = null;
			Rigidbody[] array3 = rigidbodies;
			foreach (Rigidbody bodypart in array3)
			{
				if (((Object)bodypart).name == "HIP")
				{
					enemyHip = ((Component)bodypart).gameObject;
				}
			}
			((MonoBehaviour)this).StartCoroutine(Punishment2(playerhealth, enemyHip));
			Rigidbody[] array4 = rigidbodies;
			foreach (Rigidbody rb3 in array4)
			{
				if (!((Object)(object)rb3 == (Object)null))
				{
					rb3.linearVelocity = Vector3.zero;
					rb3.AddForce(new Vector3(0f, 500f, 0f), (ForceMode)5);
				}
			}
			while ((int)hand.handState == 2)
			{
				Rigidbody[] array5 = rigidbodies;
				foreach (Rigidbody rb4 in array5)
				{
					if (!((Object)(object)rb4 == (Object)null))
					{
						rb4.AddForce(-rb2.linearVelocity * 1f, (ForceMode)5);
						rb4.AddForce(-Physics.gravity, (ForceMode)5);
					}
				}
				yield return (object)new WaitForFixedUpdate();
			}
			break;
		}
	}

	private IEnumerator ActivateFlight(Hand hand)
	{
		Debug.Log((object)"Flight Activated");
		Debug.Log((object)"Flight Activated");
		Debug.Log((object)"Flight Activated");
		Rigidbody[] array = bodyParts;
		foreach (Rigidbody rb in array)
		{
			if (!((Object)(object)rb == (Object)null))
			{
				rb.linearVelocity = Vector3.zero;
			}
		}
		startingHandPosition = ((Component)this).transform.position;
		Vector3 startingLocal = Hip.transform.InverseTransformPoint(startingHandPosition);
		yield return (object)new WaitForFixedUpdate();
		if ((Object)(object)Hip == (Object)null || bodyParts == null || bodyParts.Length == 0 || (Object)(object)hand == (Object)null)
		{
			Debug.LogWarning((object)"Flight activation failed: missing Hip, bodyParts, or hand reference.");
			yield break;
		}
		while ((int)hand.handState == 2 || (int)hand.handState == 1)
		{
			Vector3 currentLocal = Hip.transform.InverseTransformPoint(((Component)this).transform.position);
			Vector3 diffLocal = currentLocal - startingLocal;
			Vector3 worldDisplacement = Hip.transform.TransformVector(diffLocal);
			float forceScale = 0.1f;
			Rigidbody[] array2 = bodyParts;
			foreach (Rigidbody rb2 in array2)
			{
				if (!((Object)(object)rb2 == (Object)null))
				{
					Vector3 impulse = worldDisplacement * rb2.mass * forceScale;
					rb2.AddForce(-rb2.linearVelocity * 1f, (ForceMode)5);
					rb2.AddForce(-Physics.gravity, (ForceMode)5);
					if ((int)hand.handState == 2)
					{
						rb2.AddForce(impulse, (ForceMode)1);
					}
				}
			}
			yield return (object)new WaitForFixedUpdate();
		}
	}

	private IEnumerator DestroyTheWorld(Hand hand)
	{
		Debug.Log((object)"You've Doomed us all...");
		Debug.Log((object)"You've Doomed us all...");
		Debug.Log((object)"You've Doomed us all...");
		Rigidbody[] HiddenRigidbodies = Resources.FindObjectsOfTypeAll<Rigidbody>();
		Rigidbody[] array = HiddenRigidbodies;
		foreach (Rigidbody rb in array)
		{
			if (((Component)rb).gameObject.layer == LayerMask.NameToLayer("Weapons") && (Object)(object)((Component)rb).GetComponent<Weapon>() != (Object)null && ((Object)((Component)rb).gameObject).name == "Rapier")
			{
				rapier = ((Component)rb).gameObject;
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
				Debug.Log((object)((Object)((Component)rb).gameObject).name);
			}
		}
		PlayerHealth castingPlayer = ((Component)hand).GetComponentInParent<PlayerHealth>();
		if (castingPlayer.playerName != "M4GMaR" && castingPlayer.playerName != "Player 1")
		{
			Debug.Log((object)"You dont have the power of the gods...");
			yield break;
		}
		Rigidbody[] found = Object.FindObjectsByType<Rigidbody>((FindObjectsSortMode)0);
		List<Rigidbody> rigidbodies = new List<Rigidbody>(found.Length);
		Rigidbody[] array2 = found;
		foreach (Rigidbody rb2 in array2)
		{
			if (!((Object)(object)rb2 == (Object)null))
			{
				PlayerHealth playerHealth = ((Component)rb2).GetComponentInParent<PlayerHealth>();
				if (!((Object)(object)playerHealth == (Object)null) && playerHealth.alive && !((Object)(object)playerHealth == (Object)(object)castingPlayer))
				{
					rigidbodies.Add(rb2);
				}
			}
		}
		yield return (object)new WaitForFixedUpdate();
		if (rigidbodies == null || rigidbodies.Count == 0)
		{
			Debug.LogWarning((object)"There are no sinners");
			yield break;
		}
		foreach (Rigidbody rb4 in rigidbodies)
		{
			if (!((Object)(object)rb4 == (Object)null))
			{
				rb4.linearVelocity = Vector3.zero;
				rb4.AddForce(new Vector3(0f, 500f, 0f), (ForceMode)5);
				int randomValue = Random.Range(0, 10);
				if (!((Object)rb4).name.ToLower().Contains("left") && !((Object)rb4).name.ToLower().Contains("right") && randomValue < 5)
				{
					((MonoBehaviour)this).StartCoroutine(Punishment(rb4));
				}
			}
		}
		while ((int)hand.handState == 2)
		{
			foreach (Rigidbody rb3 in rigidbodies)
			{
				if (!((Object)(object)rb3 == (Object)null))
				{
					rb3.AddForce(-rb3.linearVelocity * 1f, (ForceMode)5);
					rb3.AddForce(-Physics.gravity, (ForceMode)5);
				}
			}
			yield return (object)new WaitForFixedUpdate();
		}
	}

	private IEnumerator Punishment(Rigidbody rb)
	{
		yield return (object)new WaitForSeconds(3f);
		if (!((Object)(object)rb == (Object)null) && !((Object)(object)rapier == (Object)null))
		{
			Vector3 randomDirection = Random.onUnitSphere;
			Vector3 spawnPosition = rb.position + randomDirection * 2f;
			GameObject rapierInstance = Object.Instantiate<GameObject>(rapier, spawnPosition, Quaternion.identity);
			if (NetworkServer.active)
			{
				NetworkServer.Spawn(rapierInstance, (NetworkConnection)null);
			}
			rapierInstance.transform.LookAt(((Component)rb).transform);
			Rigidbody rapierRb = rapierInstance.GetComponent<Rigidbody>();
			if ((Object)(object)rapierRb != (Object)null)
			{
				rapierRb.useGravity = false;
				yield return (object)new WaitForSeconds(1f);
				rapierInstance.transform.LookAt(((Component)rb).transform);
				Vector3 val = rb.position - rapierInstance.transform.position;
				Vector3 direction = ((Vector3)(ref val)).normalized;
				float forceMagnitude = 5000f;
				rapierRb.AddForce(direction * forceMagnitude, (ForceMode)5);
				yield return (object)new WaitForSeconds(1f);
				rapierRb.useGravity = true;
			}
			Debug.Log((object)(((Object)rb).name + " has been punished"));
		}
	}

	private IEnumerator Punishment2(PlayerHealth ph, GameObject enemyHip)
	{
		Debug.Log((object)"GET IMPALED BITCH");
		yield return (object)new WaitForSeconds(3f);
		if (!((Object)(object)ph == (Object)null) && !((Object)(object)rapier == (Object)null) && !((Object)(object)enemyHip == (Object)null))
		{
			Vector3 randomDirection = Random.onUnitSphere;
			Vector3 spawnPosition = ((Component)this).transform.position + randomDirection * 20f;
			spawnPosition += new Vector3(0f, 100f, 0f);
			GameObject rapierInstance = Object.Instantiate<GameObject>(rapier, spawnPosition, Quaternion.identity);
			rapierInstance.transform.localScale = new Vector3(1f, 1f, 3f);
			Debug.Log((object)"Rapier Instantiated correctly");
			if (NetworkServer.active)
			{
				NetworkServer.Spawn(rapierInstance, (NetworkConnection)null);
			}
			rapierInstance.transform.LookAt(enemyHip.transform);
			Rigidbody rapierRb = rapierInstance.GetComponent<Rigidbody>();
			if ((Object)(object)rapierRb != (Object)null)
			{
				rapierRb.useGravity = false;
				rapierRb.mass *= 10f;
				yield return (object)new WaitForSeconds(1f);
				rapierInstance.transform.LookAt(enemyHip.transform);
				Vector3 val = enemyHip.transform.position - rapierInstance.transform.position;
				Vector3 direction = ((Vector3)(ref val)).normalized;
				float forceMagnitude = 20000f;
				rapierRb.AddForce(direction * forceMagnitude, (ForceMode)5);
				yield return (object)new WaitForSeconds(2f);
				rapierRb.useGravity = true;
			}
			Debug.Log((object)(((Object)enemyHip).name + " has been punished"));
		}
	}
}