Decompiled source of ForceMod v1.1.0

ForceMod.dll

Decompiled 16 hours 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.1.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(1f);
		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 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)
		{
			((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_004d: 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)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		//IL_00c7: 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 * 2f;
		Vector3 val3 = val2;
		Vector3 val4 = val2 + val * 2f;
		float num = 1f;
		RaycastHit[] array = Physics.CapsuleCastAll(val3, val4, num, val, 0f);
		RaycastHit[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val5 = array2[i];
			Rigidbody attachedRigidbody = ((RaycastHit)(ref val5)).collider.attachedRigidbody;
			if (!((Object)(object)attachedRigidbody == (Object)null) && !((Object)(object)((Component)this).GetComponentInParent<PlayerHealth>() == (Object)(object)((Component)((RaycastHit)(ref val5)).collider).gameObject.GetComponentInParent<PlayerHealth>()))
			{
				GameObject val6 = new GameObject("ForceTarget");
				val6.transform.position = attachedRigidbody.position;
				val6.transform.SetParent(((Component)hand).transform, true);
				((MonoBehaviour)this).StartCoroutine(PullTowardsTarget(attachedRigidbody, val6, 8f));
				break;
			}
		}
	}

	private IEnumerator PullTowardsTarget(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 fighterJoint2 in victimHealth.playerAnimator.FighterJoints)
			{
				if ((Object)(object)fighterJoint2.jointStrength != (Object)null)
				{
					fighterJoint2.jointStrength.SetStrengthPercent(1f);
				}
			}
		}
		while (elapsed < duration && (int)hand.handState == 1)
		{
			Vector3 currentPos = ((Component)victimRb).transform.position;
			Vector3 newPos = Vector3.Lerp(currentPos, forceTarget.transform.position, 0.2f);
			Vector3 delta = newPos - currentPos;
			if (((Vector3)(ref delta)).magnitude > 0.05f)
			{
				if ((Object)(object)victimHealth != (Object)null)
				{
					Vector3 direction = ((Vector3)(ref delta)).normalized;
					((MonoBehaviour)this).StartCoroutine(bluntTransmitter.KO(victimHealth, 200f, direction, 200f));
					throwed = true;
				}
				break;
			}
			float invDt = 1f / Time.fixedDeltaTime;
			Rigidbody[] array = victimRigidBodies;
			foreach (Rigidbody rb in array)
			{
				if (!((Object)(object)rb == (Object)null))
				{
					Vector3 desiredVelocity = delta * invDt;
					Vector3 currentVelocity = rb.velocity;
					Vector3 deltaV = desiredVelocity - currentVelocity;
					Vector3 impulse = deltaV * rb.mass;
					if ((Object)(object)rb != (Object)(object)victimRb)
					{
						impulse /= 8f;
					}
					rb.AddForce(impulse, (ForceMode)1);
				}
			}
			elapsed += Time.fixedDeltaTime;
			yield return (object)new WaitForFixedUpdate();
			delta = default(Vector3);
		}
		if (!throwed && (Object)(object)victimHealth != (Object)null && (Object)(object)victimHealth.playerAnimator != (Object)null && victimHealth.playerAnimator.FighterJoints != null)
		{
			foreach (FighterJoint fighterJoint in victimHealth.playerAnimator.FighterJoints)
			{
				if ((Object)(object)fighterJoint.jointStrength != (Object)null)
				{
					fighterJoint.jointStrength.SetStrengthPercent(100f);
				}
			}
		}
		Object.Destroy((Object)(object)forceTarget);
	}
}