Decompiled source of ViolentPunch v1.0.0

BepInEx/plugins/ViolentPunch.dll

Decompiled 2 years ago
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 HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UK Sound Replacement")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UK Sound Replacement")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3326ae36-d7da-4056-a2ea-b5f06c35a607")]
[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("lapt.violentpunch", "Violent Punch", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	private static readonly Dictionary<Punch, Traverse> allPunches = new Dictionary<Punch, Traverse>();

	private static Harmony harmony;

	public void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		harmony = new Harmony("lapt.violentpunch");
		harmony.PatchAll();
	}

	public void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	public static Traverse GetPunchTraverse(Punch punch)
	{
		if ((Object)(object)punch == (Object)null)
		{
			Debug.Log((object)"Tried to get a traverse from a null punch");
			return null;
		}
		if (!allPunches.ContainsKey(punch))
		{
			Traverse value = Traverse.Create((object)punch);
			allPunches.Add(punch, value);
		}
		return allPunches[punch];
	}
}
[HarmonyPatch(typeof(FistControl), "ScrollArm")]
public static class Ensure_ArmNoChangieFromRed
{
	public static bool Prefix()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Invalid comparison between Unknown and I4
		Punch currentPunch = MonoSingleton<FistControl>.Instance.currentPunch;
		if ((currentPunch == null || (int)currentPunch.type != 1) && MonoSingleton<FistControl>.Instance.fistCooldown <= 0f)
		{
			MonoSingleton<FistControl>.Instance.ArmChange(1);
			((MonoBehaviour)MonoSingleton<FistControl>.Instance.currentPunch).Invoke("Update", 0f);
		}
		return false;
	}
}
[HarmonyPatch(typeof(FistControl), "Update")]
public static class Ensure_ArmChangieToBlue
{
	public static void Postfix()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		if (MonoSingleton<InputManager>.Instance.InputSource.Punch.WasPerformedThisFrame && (int)MonoSingleton<FistControl>.Instance.currentPunch.type != 0 && MonoSingleton<FistControl>.Instance.fistCooldown <= 0f)
		{
			MonoSingleton<FistControl>.Instance.ArmChange(0);
			((MonoBehaviour)MonoSingleton<FistControl>.Instance.currentPunch).Invoke("Update", 0f);
		}
	}
}
[HarmonyPatch(typeof(Punch), "BlastCheck")]
public static class Ensure_KBBlast
{
	public static bool Prefix(Punch __instance)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: 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_0093: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		if (MonoSingleton<InputManager>.Instance.InputSource.ChangeFist.IsPressed)
		{
			Traverse punchTraverse = Plugin.GetPunchTraverse(__instance);
			punchTraverse.Field("holdingInput").SetValue((object)false);
			punchTraverse.Field("anim").GetValue<Animator>().SetTrigger("PunchBlast");
			Vector3 val = MonoSingleton<CameraController>.Instance.GetDefaultPos() + ((Component)MonoSingleton<CameraController>.Instance).transform.forward * 2f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(MonoSingleton<CameraController>.Instance.GetDefaultPos(), ((Component)MonoSingleton<CameraController>.Instance).transform.forward, ref val2, 2f, LayerMask.op_Implicit(LayerMaskDefaults.Get((LMD)2))))
			{
				val = ((RaycastHit)(ref val2)).point - ((Component)MonoSingleton<CameraController>.Instance).gameObject.transform.forward * 0.1f;
			}
			Object.Instantiate<GameObject>(__instance.blastWave, val, ((Component)MonoSingleton<CameraController>.Instance).transform.rotation);
		}
		return false;
	}
}
[HarmonyPatch(typeof(Punch), "Update")]
public static class Inject_PunchBehavior
{
	public static bool Prefix(Punch __instance)
	{
		//IL_0044: 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_0068: Invalid comparison between Unknown and I4
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		Traverse punchTraverse = Plugin.GetPunchTraverse(__instance);
		bool value = punchTraverse.Field("shopping").GetValue<bool>();
		bool value2 = punchTraverse.Field("holdingInput").GetValue<bool>();
		if (MonoSingleton<OptionsManager>.Instance.paused)
		{
			return false;
		}
		if ((((int)__instance.type == 0 && MonoSingleton<InputManager>.Instance.InputSource.Punch.WasPerformedThisFrame) || ((int)__instance.type == 1 && MonoSingleton<InputManager>.Instance.InputSource.ChangeFist.WasPerformedThisFrame)) && __instance.ready && !value && MonoSingleton<FistControl>.Instance.fistCooldown <= 0f && MonoSingleton<FistControl>.Instance.activated && !GameStateManager.Instance.PlayerInputLocked)
		{
			float value3 = punchTraverse.Field("cooldownCost").GetValue<float>();
			FistControl instance = MonoSingleton<FistControl>.Instance;
			instance.weightCooldown += value3 * 0.25f + MonoSingleton<FistControl>.Instance.weightCooldown * value3 * 0.1f;
			FistControl instance2 = MonoSingleton<FistControl>.Instance;
			instance2.fistCooldown += MonoSingleton<FistControl>.Instance.weightCooldown;
			((MonoBehaviour)__instance).Invoke("PunchStart", 0f);
			punchTraverse.Field("holdingInput").SetValue((object)true);
		}
		if (value2 && MonoSingleton<InputManager>.Instance.InputSource.Punch.WasCanceledThisFrame)
		{
			punchTraverse.Field("holdingInput").SetValue((object)false);
		}
		float layerWeight = __instance.anim.GetLayerWeight(1);
		if (value && layerWeight < 1f)
		{
			__instance.anim.SetLayerWeight(1, Mathf.MoveTowards(layerWeight, 1f, Time.deltaTime / 10f + 5f * Time.deltaTime * (1f - layerWeight)));
		}
		else if (!value && layerWeight > 0f)
		{
			__instance.anim.SetLayerWeight(1, Mathf.MoveTowards(layerWeight, 0f, Time.deltaTime / 10f + 5f * Time.deltaTime * layerWeight));
		}
		if (!MonoSingleton<InputManager>.Instance.PerformingCheatMenuCombo() && MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasPerformedThisFrame && value)
		{
			__instance.anim.SetTrigger("ShopTap");
		}
		if (punchTraverse.Field("returnToOrigRot").GetValue<bool>())
		{
			((Component)__instance).transform.parent.localRotation = Quaternion.RotateTowards(((Component)__instance).transform.parent.localRotation, Quaternion.identity, (Quaternion.Angle(((Component)__instance).transform.parent.localRotation, Quaternion.identity) * 5f + 5f) * Time.deltaTime * 5f);
			if (((Component)__instance).transform.parent.localRotation == Quaternion.identity)
			{
				punchTraverse.Field("returnToOrigRot").SetValue((object)false);
			}
		}
		if (MonoSingleton<FistControl>.Instance.shopping && !value)
		{
			__instance.ShopMode();
		}
		else if (!MonoSingleton<FistControl>.Instance.shopping && value)
		{
			__instance.StopShop();
		}
		if (__instance.holding && Object.op_Implicit((Object)(object)__instance.heldItem))
		{
			if (!__instance.heldItem.noHoldingAnimation && MonoSingleton<FistControl>.Instance.forceNoHold <= 0)
			{
				__instance.anim.SetBool("SemiHolding", false);
				__instance.anim.SetBool("Holding", true);
				return false;
			}
			__instance.anim.SetBool("SemiHolding", true);
		}
		return false;
	}
}