Decompiled source of ForceMod v1.2.0

ForceMod.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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
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("ForceMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ForceMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b93d2d9b-4a03-4ce2-af75-9223be2ee4e8")]
[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.ForceMod", "Force Mod", "1.2.0")]
public class ForceMod : BaseUnityPlugin
{
	public static ForceMod Instance { get; private set; }

	private void Awake()
	{
		((Object)Chainloader.ManagerObject).hideFlags = (HideFlags)61;
		Instance = this;
		Harmony.CreateAndPatchAll(typeof(ForceMod), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"AWAKE: Hooking into SceneManager.sceneLoaded");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)("SCENE LOADED: " + ((Scene)(ref scene)).name));
		((MonoBehaviour)this).StartCoroutine(DelayedSetup());
	}

	public IEnumerator DelayedSetup()
	{
		yield return (object)new WaitForSecondsRealtime(3f);
		Hand[] hands = Object.FindObjectsOfType<Hand>();
		if (hands == null)
		{
			yield break;
		}
		Hand[] array = hands;
		foreach (Hand hand in array)
		{
			GameObject go = ((Component)((Component)hand).transform.parent).gameObject;
			if ((Object)(object)go.GetComponent<ForceTransmitter>() == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Hand found " + ((Object)((Component)hand).gameObject).name));
				go.AddComponent<ForceTransmitter>();
			}
		}
	}
}
public class ForceTransmitter : MonoBehaviour
{
	private BluntTransmitter bluntTransmitter;

	private Hand hand;

	private PlayerHealth playerHealth;

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

	private bool canUseForce = true;

	private readonly float forceCooldown = 15f;

	private void Start()
	{
		bluntTransmitter = ((Component)this).GetComponent<BluntTransmitter>();
		hand = ((Component)this).GetComponentInChildren<Hand>();
		playerHealth = ((Component)this).GetComponentInParent<PlayerHealth>();
		if ((Object)(object)hand != (Object)null && (Object)(object)playerHealth != (Object)null && !((Object)((Component)this).gameObject).name.ToLower().Contains("elbow"))
		{
			((MonoBehaviour)this).StartCoroutine(ForceLoop());
		}
	}

	private IEnumerator ForceLoop()
	{
		yield return (object)new WaitForEndOfFrame();
		HandState previousState = hand.handState;
		while ((Object)(object)playerHealth != (Object)null)
		{
			HandState currentState = hand.handState;
			if (currentState != previousState)
			{
				stateHistory.Add(currentState);
				if (stateHistory.Count > 8)
				{
					stateHistory.RemoveAt(0);
				}
				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] == 2 && (int)stateHistory[7] == 1)
				{
					ActivateForce(hand);
					stateHistory.Clear();
				}
				previousState = currentState;
			}
			else
			{
				stateHistory.Clear();
			}
			yield return (object)new WaitForSeconds(0.25f);
		}
	}

	private void ActivateForce(Hand hand)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: 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_0037: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = -((Component)this).transform.up;
		Vector3 val2 = ((Component)this).transform.position + val * 1.5f;
		Vector3 val3 = val2;
		Vector3 val4 = val2 + val * 4f;
		float num = 1f;
		Collider[] array = Physics.OverlapCapsule(val3, val4, num);
		if (!canUseForce)
		{
			return;
		}
		Collider[] array2 = array;
		foreach (Collider val5 in array2)
		{
			Rigidbody attachedRigidbody = val5.attachedRigidbody;
			if (!((Object)(object)attachedRigidbody == (Object)null) && !((Object)(object)((Component)this).GetComponentInParent<PlayerHealth>() == (Object)(object)((Component)val5).gameObject.GetComponentInParent<PlayerHealth>()) && !val5.isTrigger)
			{
				((MonoBehaviour)this).StartCoroutine(ForceCooldown());
				GameObject val6 = new GameObject("ForceTarget");
				val6.transform.position = attachedRigidbody.position;
				val6.transform.SetParent(((Component)hand).transform, true);
				((MonoBehaviour)this).StartCoroutine(ForceGrabbing(attachedRigidbody, val6, 8f));
				break;
			}
		}
	}

	private IEnumerator ForceGrabbing(Rigidbody victimRb, GameObject forceTarget, float duration)
	{
		float elapsed = 0f;
		PlayerHealth victimHealth = ((Component)victimRb).GetComponentInParent<PlayerHealth>();
		Rigidbody[] victimRigidBodies = (Rigidbody[])((!((Object)(object)victimHealth != (Object)null)) ? ((Array)new Rigidbody[1] { victimRb }) : ((Array)((Component)victimHealth).GetComponentsInChildren<Rigidbody>()));
		bool throwed = false;
		if ((Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.playerAnimator != (Object)null && victimHealth.playerAnimator.FighterJoints != null)
		{
			foreach (FighterJoint joint2 in victimHealth.playerAnimator.FighterJoints)
			{
				JointStrength jointStrength = joint2.jointStrength;
				if (jointStrength != null)
				{
					jointStrength.SetStrengthPercent(20f);
				}
			}
		}
		JointDrive val;
		if ((Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.ballHolderjoint != (Object)null)
		{
			ConfigurableJoint ballHolderjoint = victimHealth.ballHolderjoint;
			val = default(JointDrive);
			((JointDrive)(ref val)).positionSpring = 20f;
			((JointDrive)(ref val)).positionDamper = 20f;
			((JointDrive)(ref val)).maximumForce = 20f;
			ballHolderjoint.angularXDrive = val;
			ConfigurableJoint ballHolderjoint2 = victimHealth.ballHolderjoint;
			val = default(JointDrive);
			((JointDrive)(ref val)).positionSpring = 20f;
			((JointDrive)(ref val)).positionDamper = 20f;
			((JointDrive)(ref val)).maximumForce = 20f;
			ballHolderjoint2.angularYZDrive = val;
		}
		Quaternion rotationOffset = Quaternion.Inverse(((Component)this).transform.rotation) * victimRb.rotation;
		float angleDeg = default(float);
		Vector3 axis = default(Vector3);
		while (elapsed < duration && (int)hand.handState > 0)
		{
			if ((int)hand.handState == 1)
			{
				Vector3 currentPos2 = victimRb.position;
				Vector3 targetPos2 = forceTarget.transform.position;
				Vector3 newPos2 = Vector3.Lerp(currentPos2, targetPos2, 0.05f);
				Vector3 delta2 = newPos2 - currentPos2;
				float invDt2 = 1f / Time.fixedDeltaTime;
				Rigidbody[] array = victimRigidBodies;
				foreach (Rigidbody rb2 in array)
				{
					if (!((Object)(object)rb2 == (Object)null))
					{
						Vector3 desiredV2 = delta2 * invDt2;
						Vector3 deltaV2 = desiredV2 - (victimRb.velocity + victimRb.velocity + victimRb.velocity + rb2.velocity) / 4f;
						Vector3 impulse2 = deltaV2 * rb2.mass;
						if ((Object)(object)rb2 != (Object)(object)victimRb)
						{
							impulse2 /= 4f;
						}
						rb2.AddForce(impulse2, (ForceMode)1);
					}
				}
				Quaternion targetRot = ((Component)this).transform.rotation * rotationOffset;
				Quaternion deltaQ = targetRot * Quaternion.Inverse(victimRb.rotation);
				((Quaternion)(ref deltaQ)).ToAngleAxis(ref angleDeg, ref axis);
				if (angleDeg > 180f)
				{
					angleDeg -= 360f;
				}
				float angleRad = angleDeg * ((float)Math.PI / 180f);
				Vector3 torqueImpulse = ((Vector3)(ref axis)).normalized * (angleRad * 5f);
				victimRb.AddTorque(torqueImpulse, (ForceMode)1);
				deltaQ = default(Quaternion);
				axis = default(Vector3);
				if (((Vector3)(ref delta2)).magnitude > 0.05f)
				{
					if (!((Object)(object)victimHealth != (Object)null))
					{
						break;
					}
					_ = ((Vector3)(ref delta2)).normalized;
					victimHealth.bloodAmount -= 0.6000000238418579;
					if (victimHealth.bloodAmount <= 0.0)
					{
						((MonoBehaviour)this).StartCoroutine(bluntTransmitter.KO(victimHealth, 200f, Vector3.zero, 200f));
						victimHealth.Die((DeathReason)3);
					}
					Rigidbody[] array2 = victimRigidBodies;
					foreach (Rigidbody rb3 in array2)
					{
						if ((Object)(object)rb3 == (Object)null)
						{
							continue;
						}
						Vector3 desiredV3 = delta2 * invDt2;
						Vector3 deltaV3 = desiredV3 - (victimRb.velocity + victimRb.velocity + victimRb.velocity + rb3.velocity) / 4f;
						Vector3 impulse3 = deltaV3 * rb3.mass;
						if ((Object)(object)rb3 != (Object)(object)victimRb)
						{
							impulse3 /= 4f;
						}
						rb3.AddForce(impulse3, (ForceMode)1);
						if ((Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.playerAnimator != (Object)null && victimHealth.playerAnimator.FighterJoints != null)
						{
							foreach (FighterJoint joint in victimHealth.playerAnimator.FighterJoints)
							{
								JointStrength jointStrength2 = joint.jointStrength;
								if (jointStrength2 != null)
								{
									jointStrength2.SetStrengthPercent(1f);
								}
							}
						}
						if ((Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.ballHolderjoint != (Object)null)
						{
							ConfigurableJoint ballHolderjoint3 = victimHealth.ballHolderjoint;
							val = default(JointDrive);
							((JointDrive)(ref val)).positionSpring = 1f;
							((JointDrive)(ref val)).positionDamper = 1f;
							((JointDrive)(ref val)).maximumForce = 1f;
							ballHolderjoint3.angularXDrive = val;
							ConfigurableJoint ballHolderjoint4 = victimHealth.ballHolderjoint;
							val = default(JointDrive);
							((JointDrive)(ref val)).positionSpring = 1f;
							((JointDrive)(ref val)).positionDamper = 1f;
							((JointDrive)(ref val)).maximumForce = 1f;
							ballHolderjoint4.angularYZDrive = val;
						}
						((MonoBehaviour)this).StartCoroutine(bluntTransmitter.RestoreBallHolderJoint(victimHealth, 3f));
					}
					throwed = true;
					break;
				}
				delta2 = default(Vector3);
			}
			else
			{
				Vector3 currentPos = victimRb.position;
				Vector3 targetPos = ((Component)hand).transform.position - ((Component)this).transform.up / 3f;
				Vector3 newPos = Vector3.Lerp(currentPos, targetPos, 0.05f);
				Vector3 delta = newPos - currentPos;
				float invDt = 1f / Time.fixedDeltaTime;
				Rigidbody[] array3 = victimRigidBodies;
				foreach (Rigidbody rb in array3)
				{
					if (!((Object)(object)rb == (Object)null))
					{
						Vector3 desiredV = delta * invDt;
						Vector3 deltaV = desiredV - (victimRb.velocity + victimRb.velocity + victimRb.velocity + rb.velocity) / 4f;
						Vector3 impulse = deltaV * rb.mass;
						if ((Object)(object)rb != (Object)(object)victimRb)
						{
							impulse /= 4f;
						}
						rb.AddForce(impulse, (ForceMode)1);
					}
				}
			}
			elapsed += Time.fixedDeltaTime;
			yield return (object)new WaitForFixedUpdate();
		}
		if (!throwed && (Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.playerAnimator != (Object)null && victimHealth.playerAnimator.FighterJoints != null)
		{
			((MonoBehaviour)this).StartCoroutine(bluntTransmitter.RestoreBallHolderJoint(victimHealth, 1f));
		}
		Object.Destroy((Object)(object)forceTarget);
	}

	private IEnumerator ForceCooldown()
	{
		canUseForce = false;
		yield return (object)new WaitForSeconds(forceCooldown);
		canUseForce = true;
	}
}