Decompiled source of Force Punches v1.0.1

Mods/forcepunches.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using MelonLoader;
using MelonLoader.Preferences;
using ModThatIsNotMod;
using ModThatIsNotMod.BoneMenu;
using ParryMod;
using StressLevelZero.Interaction;
using StressLevelZero.Rig;
using UnhollowerBaseLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Force punch", "1.0.0", "ffba", null)]
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: AssemblyTitle("if_ur_reading_this_ur_gay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("if_ur_reading_this_ur_gay")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("59a3d1b7-7284-47d8-bd5f-14376897d8f2")]
[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 ParryMod;

public class Main : MelonMod
{
	private MelonPreferences_Category prefCategory;

	public MelonPreferences_Entry<float> prefMinVelocity;

	public MelonPreferences_Entry<float> prefParryRadius;

	public MelonPreferences_Entry<float> prefReflectStrength;

	public MelonPreferences_Entry<float> prefPushForce;

	public MelonPreferences_Entry<bool> prefShowVisuals;

	private LineRenderer parryVisual;

	private GameObject visualObj;

	private float parryActiveTimer;

	private Vector3 lastTriggerPos;

	private Vector3 leftLastPos;

	private Vector3 rightLastPos;

	private float leftSpeed;

	private float rightSpeed;

	private const float DEG2RAD = (float)Math.PI / 180f;

	public override void OnApplicationStart()
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		prefCategory = MelonPreferences.CreateCategory("ParrySettings");
		prefMinVelocity = prefCategory.CreateEntry<float>("MinHandVelocity", 0.1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefParryRadius = prefCategory.CreateEntry<float>("ParryRadius", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefReflectStrength = prefCategory.CreateEntry<float>("ReflectStrength", -5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefPushForce = prefCategory.CreateEntry<float>("PushForce", 15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		prefShowVisuals = prefCategory.CreateEntry<bool>("ShowVisuals", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MenuCategory obj = MenuManager.CreateCategory("Force punch", Color.yellow);
		obj.CreateFloatElement("Trigger Speed", Color.white, prefMinVelocity.Value, (Action<float>)delegate(float v)
		{
			prefMinVelocity.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0f, 10f, false);
		obj.CreateFloatElement("Strength", Color.red, prefReflectStrength.Value, (Action<float>)delegate(float v)
		{
			prefReflectStrength.Value = v;
			prefCategory.SaveToFile(true);
		}, 1f, -15f, -1f, false);
		obj.CreateFloatElement("Push Force", Color.magenta, prefPushForce.Value, (Action<float>)delegate(float v)
		{
			prefPushForce.Value = v;
			prefCategory.SaveToFile(true);
		}, 1f, 0f, 50f, false);
		obj.CreateFloatElement("Radius", Color.white, prefParryRadius.Value, (Action<float>)delegate(float v)
		{
			prefParryRadius.Value = v;
			prefCategory.SaveToFile(true);
		}, 0.1f, 0.1f, 2f, false);
		obj.CreateBoolElement("Show Visuals", Color.yellow, prefShowVisuals.Value, (Action<bool>)delegate(bool v)
		{
			prefShowVisuals.Value = v;
			prefCategory.SaveToFile(true);
		});
	}

	public override void OnUpdate()
	{
		if (!((Object)(object)Player.GetRigManager() == (Object)null))
		{
			if ((Object)(object)visualObj == (Object)null)
			{
				CreateVisuals();
			}
			CalculateManualVelocity();
			if (leftSpeed > prefMinVelocity.Value)
			{
				ExecuteParry(Player.leftHand);
			}
			if (rightSpeed > prefMinVelocity.Value)
			{
				ExecuteParry(Player.rightHand);
			}
			UpdateVisualEffect();
		}
	}

	private void CalculateManualVelocity()
	{
		//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_0020: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val;
		if ((Object)(object)Player.leftBaseController != (Object)null)
		{
			Vector3 position = ((Component)Player.leftBaseController).transform.position;
			val = position - leftLastPos;
			leftSpeed = ((Vector3)(ref val)).magnitude / Time.deltaTime;
			leftLastPos = position;
		}
		if ((Object)(object)Player.rightBaseController != (Object)null)
		{
			Vector3 position2 = ((Component)Player.rightBaseController).transform.position;
			val = position2 - rightLastPos;
			rightSpeed = ((Vector3)(ref val)).magnitude / Time.deltaTime;
			rightLastPos = position2;
		}
	}

	private void ExecuteParry(Hand hand)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)hand == (Object)null)
		{
			return;
		}
		Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(((Component)hand).transform.position, prefParryRadius.Value));
		bool flag = false;
		Collider[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			Rigidbody attachedRigidbody = array2[i].attachedRigidbody;
			if (!((Object)(object)attachedRigidbody == (Object)null) && !attachedRigidbody.isKinematic && !((Object)(object)((Component)attachedRigidbody).GetComponentInParent<RigManager>() != (Object)null) && !IsItemHeld(attachedRigidbody))
			{
				attachedRigidbody.velocity *= prefReflectStrength.Value;
				Vector3 val = attachedRigidbody.worldCenterOfMass - ((Component)hand).transform.position;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				attachedRigidbody.AddForce(normalized * prefPushForce.Value, (ForceMode)2);
				flag = true;
			}
		}
		if (flag)
		{
			lastTriggerPos = ((Component)hand).transform.position;
			parryActiveTimer = 0.12f;
		}
	}

	private bool IsItemHeld(Rigidbody rb)
	{
		Hand leftHand = Player.leftHand;
		if ((Object)(object)((leftHand != null) ? leftHand.m_CurrentAttachedObject : null) != (Object)null && (Object)(object)Player.leftHand.m_CurrentAttachedObject.GetComponentInParent<Rigidbody>() == (Object)(object)rb)
		{
			return true;
		}
		Hand rightHand = Player.rightHand;
		if ((Object)(object)((rightHand != null) ? rightHand.m_CurrentAttachedObject : null) != (Object)null && (Object)(object)Player.rightHand.m_CurrentAttachedObject.GetComponentInParent<Rigidbody>() == (Object)(object)rb)
		{
			return true;
		}
		return false;
	}

	private void CreateVisuals()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		//IL_0041: 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)
		visualObj = new GameObject("ParryVisualContainer");
		parryVisual = visualObj.AddComponent<LineRenderer>();
		((Renderer)parryVisual).material = new Material(Shader.Find("Sprites/Default"));
		parryVisual.startColor = Color.yellow;
		parryVisual.endColor = Color.white;
		parryVisual.startWidth = 0.05f;
		parryVisual.endWidth = 0.05f;
		parryVisual.positionCount = 16;
		parryVisual.loop = true;
		((Renderer)parryVisual).enabled = false;
	}

	private void UpdateVisualEffect()
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		if (parryActiveTimer > 0f && prefShowVisuals.Value)
		{
			parryActiveTimer -= Time.deltaTime;
			((Renderer)parryVisual).enabled = true;
			float num = 22.5f;
			for (int i = 0; i < 16; i++)
			{
				float num2 = (float)i * num * ((float)Math.PI / 180f);
				Vector3 val = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * prefParryRadius.Value;
				parryVisual.SetPosition(i, lastTriggerPos + val);
			}
		}
		else
		{
			if ((Object)(object)parryVisual != (Object)null)
			{
				((Renderer)parryVisual).enabled = false;
			}
			if (parryActiveTimer > 0f)
			{
				parryActiveTimer -= Time.deltaTime;
			}
		}
	}
}