Decompiled source of OnePunch v1.1.0

OnePunch.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using OnePunch;
using ScheduleOne.Combat;
using ScheduleOne.DevUtilities;
using ScheduleOne.PlayerScripts;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::OnePunch.OnePunch), "OnePunch", "1.1.0", "ByteOfRamen", null)]
[assembly: MelonColor]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("OnePunch")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OnePunch")]
[assembly: AssemblyTitle("OnePunch")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OnePunch;

public static class BuildInfo
{
	public const string Name = "OnePunch";

	public const string Description = "One Punch Knockout!";

	public const string Author = "ByteOfRamen";

	public const string Version = "1.1.0";
}
public class OnePunch : MelonMod
{
	[HarmonyPatch(typeof(PunchController), "ExecuteHit")]
	public class PunchControllerExecuteHitPatch
	{
		private static float originalMinDamage;

		private static float originalMaxDamage;

		private static float originalMinForce;

		private static float originalMaxForce;

		public static void Prefix(PunchController __instance, float power)
		{
			originalMinDamage = __instance.MinPunchDamage;
			originalMaxDamage = __instance.MaxPunchDamage;
			originalMinForce = __instance.MinPunchForce;
			originalMaxForce = __instance.MaxPunchForce;
			if (power >= 0.9f)
			{
				__instance.MinPunchDamage = _HeavyMinPunchDamage.Value;
				__instance.MaxPunchDamage = _HeavyMaxPunchDamage.Value;
			}
			else
			{
				__instance.MinPunchDamage = _LightMinPunchDamage.Value;
				__instance.MaxPunchDamage = _LightMaxPunchDamage.Value;
			}
			__instance.MinPunchForce = originalMinForce * _PunchForceMultiplierEntry.Value;
			__instance.MaxPunchForce = originalMaxForce * _PunchForceMultiplierEntry.Value;
		}

		public static void Postfix(PunchController __instance, float power)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (power >= 0.9f && _UseExplosionForceEntry.Value && PlayerSingleton<PlayerCamera>.Instance.LookRaycast(1.25f, ref val, NetworkSingleton<CombatManager>.Instance.MeleeLayerMask, true, 0.3f))
			{
				IDamageable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<IDamageable>();
				if (componentInParent != null)
				{
					Rigidbody attachedRigidbody = ((RaycastHit)(ref val)).collider.attachedRigidbody;
					if ((Object)(object)attachedRigidbody != (Object)null)
					{
						attachedRigidbody.AddExplosionForce(_ExplosionForceMultiplierEntry.Value, ((RaycastHit)(ref val)).point, _ExplosionRadiusEntry.Value, _ExplosionLiftEntry.Value, (ForceMode)1);
					}
				}
			}
			__instance.MinPunchDamage = originalMinDamage;
			__instance.MaxPunchDamage = originalMaxDamage;
			__instance.MinPunchForce = originalMinForce;
			__instance.MaxPunchForce = originalMaxForce;
		}
	}

	public class KnockoutLauncher : MonoBehaviour
	{
		private bool _hasLaunched = false;

		private Rigidbody _rb;

		public Vector3 LaunchDirection { get; set; }

		private void Awake()
		{
			_rb = ((Component)this).GetComponent<Rigidbody>();
		}

		private void FixedUpdate()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!_hasLaunched && Object.op_Implicit((Object)(object)_rb))
			{
				_rb.AddForce(LaunchDirection * _PunchForceMultiplierEntry.Value, (ForceMode)1);
				_hasLaunched = true;
				Object.Destroy((Object)(object)this, 0.1f);
			}
		}
	}

	private static MelonPreferences_Category _configCategory;

	private static MelonPreferences_Entry<float> _PunchForceMultiplierEntry;

	private static MelonPreferences_Entry<float> _LightMinPunchDamage;

	private static MelonPreferences_Entry<float> _LightMaxPunchDamage;

	private static MelonPreferences_Entry<float> _HeavyMinPunchDamage;

	private static MelonPreferences_Entry<float> _HeavyMaxPunchDamage;

	private static MelonPreferences_Entry<bool> _UseExplosionForceEntry;

	private static MelonPreferences_Entry<float> _ExplosionForceMultiplierEntry;

	private static MelonPreferences_Entry<float> _ExplosionRadiusEntry;

	private static MelonPreferences_Entry<float> _ExplosionLiftEntry;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("OnePunch Initialized!");
		_configCategory = MelonPreferences.CreateCategory("OnePunch");
		_PunchForceMultiplierEntry = _configCategory.CreateEntry<float>("PunchForceMultiplier", 4f, "Controls the strength of punches for knockouts. Higher values increase punch power dramatically. Recommended range: 1–50. (normal 1.0 | default 4.0)", (string)null, false, false, (ValueValidator)null, (string)null);
		_LightMinPunchDamage = _configCategory.CreateEntry<float>("LightMinPunchDamage", 20f, "Minimum damage for light punches. Adjust this to change how weak light punches are. (default: 20)", (string)null, false, false, (ValueValidator)null, (string)null);
		_LightMaxPunchDamage = _configCategory.CreateEntry<float>("LightMaxPunchDamage", 60f, "Maximum damage for light punches. Adjust this to change how weak light punches are. (default: 60)", (string)null, false, false, (ValueValidator)null, (string)null);
		_HeavyMinPunchDamage = _configCategory.CreateEntry<float>("HeavyMinPunchDamage", 50f, "Minimum damage for heavy punches. Adjust this to change how powerful heavy punches are. (default: 50 | Game Dev Default: 20)", (string)null, false, false, (ValueValidator)null, (string)null);
		_HeavyMaxPunchDamage = _configCategory.CreateEntry<float>("HeavyMaxPunchDamage", 200f, "Maximum damage for heavy punches. Adjust this to change how powerful heavy punches are. (default: 200) | Game Dev Default: 60", (string)null, false, false, (ValueValidator)null, (string)null);
		_UseExplosionForceEntry = _configCategory.CreateEntry<bool>("UseExplosionForce", true, "If enabled, adds an explosion-style force on heavy punches to dramatically launch NPCs. (default: true)", (string)null, false, false, (ValueValidator)null, (string)null);
		_ExplosionForceMultiplierEntry = _configCategory.CreateEntry<float>("ExplosionForceMultiplier", 1000f, "Multiplier for explosion force. Higher values increase the intensity of the explosion force applied on heavy punches. (default: 1000)", (string)null, false, false, (ValueValidator)null, (string)null);
		_ExplosionRadiusEntry = _configCategory.CreateEntry<float>("ExplosionRadius", 2f, "Radius of the explosion force. Higher values increase the area affected by the explosion force. (default: 2)", (string)null, false, false, (ValueValidator)null, (string)null);
		_ExplosionLiftEntry = _configCategory.CreateEntry<float>("ExplosionLift", 0.5f, "Lift factor for the explosion force. This controls how much 'vertical' force is applied along with the explosion. (default:0.5)", (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPreferences.Save();
	}
}